print '--------------begin-enumerate------------------'
# enumerate用于遍历序列中的元素以及它们的下标
for i, j in enumerate(('a', 'b', 'c')):
print 'i = %d, j = %s' % (i, j)
for i, j in enumerate([1, 2, 3]):
print 'i = %d, j = %d' % (i, j)
print '--------------end-enumerate------------------'
输出:
--------------begin-enumerate------------------
i = 0, j = a
i = 1, j = b
i = 2, j = c
i = 0, j = 1
i = 1, j = 2
i = 2, j = 3
--------------end-enumerate------------------