enumerate [ɪˈnuːməreɪt]
class enumerate(object):
"""
Return an enumerate object. 返回一个enum对象
iterable
an object supporting 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]), ...
"""
def __init__(self, iterable, start=0): # known special case of enumerate.__init__
""" Initialize self. See help(type(self)) for accurate signature. """
pass
# enumerate(obj)
e = enumerate("baicao")
for i in e:
print(i, end=" ")
# (0, 'b') (1, 'a') (2, 'i') (3, 'c') (4, 'a') (5, 'o')
# enumerate(obj,start) start表示,enum对象下标的起始位置
e = enumerate("baicao",3)
for i in e:
print(i)
# (3, 'b')
# (4, 'a')
# (5, 'i')
# (6, 'c')
# (7, 'a')
# (8, 'o')
网友评论