posts - 403, comments - 310, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          在Python的for循環中計數

          Posted on 2007-12-25 21:29 ZelluX 閱讀(3885) 評論(0)  編輯  收藏 所屬分類: Scripting

          利用enumerate

          for i, obj in enumerate(list):
              print i, obj

          Help on class enumerate in module __builtin__:

          class enumerate(object)
           |  enumerate(iterable) -> iterator for index, value of iterable
           |
           |  Return an enumerate object.  iterable must be an other object that supports
           |  iteration.  The enumerate object yields pairs containing a count (from
           |  zero) and a value yielded by the iterable argument.  enumerate is useful
           |  for obtaining an indexed list: (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
           |
           |  Methods defined here:
           |
           |  __getattribute__(...)
           |      x.__getattribute__('name') <==> x.name
           |
           |  __iter__(...)
           |      x.__iter__() <==> iter(x)
           |
           |  next(...)
           |      x.next() -> the next value, or raise StopIteration
           |
           |  ----------------------------------------------------------------------
           |  Data and other attributes defined here:
           |
           |  __new__ = <built-in method __new__ of type object at 0xb7f35d20>
           |      T.__new__(S, ...) -> a new object with type S, a subtype of T

          主站蜘蛛池模板: 高要市| 天长市| 长武县| 霍州市| 含山县| 昆山市| 象州县| 浮梁县| 巴彦县| 屏山县| 宣武区| 黄石市| 乌拉特中旗| 东乡| 抚宁县| 商洛市| 崇文区| 三江| 玉树县| 江门市| 安岳县| 固安县| 泊头市| 获嘉县| 津市市| 邛崃市| 赣州市| 宁安市| 南通市| 中卫市| 共和县| 沅陵县| 新泰市| 清苑县| 囊谦县| 申扎县| 临澧县| 张家口市| 玉林市| 雷山县| 临汾市|