python enumerate()

enumerate(iterabe[,start])

这个函数是一个迭代器?

可以给一个迭代器后面[]是起始的位置

 如果[]中给了10则会从10开始

 

class enumerate(object):
    """
    enumerate(iterable[, start]) -> iterator for index, value of iterable
    
    Return an enumerate object.  iterable must be another object that supports
    iteration.  The enumerate object yields pairs containing a count (from
    start, which defaults to 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]), ...
    """
example:
=============================== >>> a=enumerate(range(5),4) >>> a <enumerate object at 0x000001B4AD750BD0> >>> print(a) <enumerate object at 0x000001B4AD750BD0> >>> for i,j in a: print(i,j) 4 0 5 1 6 2 7 3 8 4 >>>

 

posted @ 2017-01-29 00:56  ezway  阅读(235)  评论(0编辑  收藏  举报