python中enumerate函数
2021/5/1 22:25:51
本文主要是介绍python中enumerate函数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
python中enumerate函数。
1、python中enumerate函数
enumerate函数的应用对象为序列(列表、元组、字符串), 返回一个由二元组组成的可迭代对象,二元组由可迭代参数的索引号及其对应的元素组成。
列表
>>> test1 = ["aaa","bbb","ccc"] >>> for i in enumerate(test1): print(i) (0, 'aaa') (1, 'bbb') (2, 'ccc')
元组
>>> test1 = ("aa","bb","cc") >>> for i in enumerate(test1): print(i) (0, 'aa') (1, 'bb') (2, 'cc')
字符串
>>> test1 = "abcde" >>> for i in enumerate(test1): print(i) (0, 'a') (1, 'b') (2, 'c') (3, 'd') (4, 'e')
这篇关于python中enumerate函数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python