- enumerate(sequence, start=0)
- Return an enumerate object. sequence must be a sequence, an
iterator, or some other object which supports iteration. The
next() method of the iterator returned by enumerate() returns a
tuple containing a count (from start which defaults to 0) and the
values obtained from iterating over sequence:
vault = "abcdefg"
print type(enumerate(vault))
print list(enumerate(vault))for index, x in enumerate(vault):
result:
print index, x
<type 'enumerate'> [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (5, 'f'), (6, 'g')] 0 a 1 b 2 c 3 d 4 e 5 f 6 g
沒有留言:
張貼留言