Python enumerate

>>> a = [1, 2, 3]
>>> for index, item in enumerate(a):
    print index, item    
1
2
3

>>> b = (1, 2, 3)
>>> for index, item in enumerate(b):
    print index, item    
1
2
3

>>> c = {'a':1, 'b':2, 'c':3}
>>> for index, item in enumerate(c):
    print index, item
a
c
b

>>> d = "hello world"
>>> for index, item in enumerate(d):
    print index, item 
h
e
l
l
o
 
w
o
r
l
d


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章