python enumerate函数用法
来源:互联网 发布:淘宝流量有什么作用 编辑:程序博客网 时间:2024/06/15 18:52
eunmerate在英文中是列举、枚举的意思,在python中eunmerate()是一个内置的函数,用于在一个可迭代或可遍历的对象(如列表、字符串、数组、字典)中,将对象组成一个一个序列和索引,可以同时获得索引和索引值。
enumerate函数原型:
enumerate(sequence, [start=0])功能:将可循环序列sequence以start开始分别列出序列数据和数据下标;
即对一个可遍历的数据对象(如列表、元组或字符串),enumerate会将该数据对象组合为一个索引序列,同时列出数据和数据下标;
对于一个列表list1,同时列出索引和每一个元素:
list1 = ['A','B','C','D','E']for index, item in enumerate(list1): print index, item
输出:
0 A1 B2 C3 E4 F
enumerate还可以接受第二个参数start,仍会从第一个索引值开始,遍历完所有的索引值,但列出来的索引起始值是从start开始(默认为0):
list1 = ['A','B','C','D','E']for index, item in enumerate(list1,10): print index, item输出:
10 A11 B12 C13 D14 E
enumerate用于字符串:
str = 'ABCDE'for index , item in enumerate(str): print index , item输出:
0 A1 B2 C3 E4 F
阅读全文
0 0
- python enumerate函数用法
- python enumerate()函数 用法
- python中enumerate函数用法
- python 函数-enumerate的用法
- Python中enumerate()函数的用法
- python中的enumerate函数的用法
- python中enumerate()函数的用法
- python内置函数:enumerate用法总结
- python --enumerate用法
- python中enumerate用法
- python enumerate 用法
- python enumerate 用法
- Python enumerate用法
- python enumerate 的用法
- python enumerate用法
- python --enumerate用法
- python enumerate 用法
- Python中enumerate用法
- 读-写锁ReadWriteLock
- hive查询如何显示查询的字段
- LeetCode513. Find Bottom Left Tree Value
- Unbuntu16.04+Kaldi本地运行thchs30语料(完整版)
- QNetwork封装的一个get/post类
- python enumerate函数用法
- Linux初探---------基本介绍及常见发行版
- 51nod 1563 坐标轴上的最大团 (贪心)
- php基础
- 写程序学ML:朴素贝叶斯算法原理及实现(三)
- android学习---使用GSON解析JSON格式数据
- 10月1日(周日训练笔记)
- hdu 4027 Can you answer these queries?-特殊的单节点更新
- 日常作业2