python中enumerate 函数
2016-04-16 16:27
549 查看
enumerate 函数用于遍历序列中的元素以及它们的下标:
>>> for i,j in enumerate(('a','b','c')):
print i,j
0 a
1 b
2 c
>>> for i,j in enumerate([1,2,3]):
print i,j
0 1
1 2
2 3
>>> for i,j in enumerate({'a':1,'b':2}):
print i,j
0 a
1 b
>>> for i,j in enumerate('abc'):
print i,j
0 a
1 b
2 c
>>> for i,j in enumerate(('a','b','c')):
print i,j
0 a
1 b
2 c
>>> for i,j in enumerate([1,2,3]):
print i,j
0 1
1 2
2 3
>>> for i,j in enumerate({'a':1,'b':2}):
print i,j
0 a
1 b
>>> for i,j in enumerate('abc'):
print i,j
0 a
1 b
2 c
相关文章推荐
- Python 练习实例29
- Python字典(Dictionary)
- python调试
- 递归实现前向匹配分词
- Python 练习实例28
- Python核心编程——快速入门
- Python元组
- Python列表(List)
- Python L suffix - indicated long integer literals before Python3
- python 爬虫demo
- Python install easy_install and pip
- Python 练习实例27
- Python字符串
- Python 练习实例26
- 用Python 做科学计算
- python:inspect函数自动生成函数名
- python常用常用函数
- Python 练习实例25
- Python数字
- python画log图