Skip to content

Latest commit

 

History

History
27 lines (22 loc) · 380 Bytes

File metadata and controls

27 lines (22 loc) · 380 Bytes

普通写法获取列表元素的下标

>>> furits = ["apple", "orange", "banala"]
>>> index  = 0
>>> for f in furits:
...     print(index, f)
...     index += 1
...
0 apple
1 orange
2 banala

pythonic 方法:用 enumerate 获取元素下标

>>> for index, item in enumerate(furits):
...     print(index, item)
...
0 apple
1 orange
2 banala
>>>