python enumerate() 使用
来源:互联网 发布:成绩管理系统c程序软件 编辑:程序博客网 时间:2024/06/11 07:06
在python中实用enumerate() function。
在对列表遍历的时候,我们使用for进行遍历,今天学习到enumerate()可以同时在使用index和value时用。
目前只在列表中使用。方法解释:
def __init__(self, iterable, start=0): # known special case of enumerate.__init__ """ Initialize self. See help(type(self)) for accurate signature. """ pass
>>> for i,ele in enumerate(list_test):
... print(i,ele)
...
0 dad
1 dasddaas
2 dasdsadasdasd
使用enumerate()更加有效率,更加方便。
以下在python 中的摘要:
- class enumerate(object)
- | enumerate(iterable[, start]) -> iterator for index, value of iterable #迭代器的索引,迭代器的值
- |
- | Return an enumerate object. iterable must be another object that supports
- | iteration. The enumerate object yields pairs containing a count (from
- | start, which defaults to zero) and a value yielded by the iterable argument.
- | enumerate is useful for obtaining an indexed list:
- | (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
- |
- | Methods defined here:
- |
- | __getattribute__(...)
- | x.__getattribute__('name') <==> x.name
- |
- | __iter__(...)
- | x.__iter__() <==> iter(x)
- |
- | next(...)
- | x.next() -> the next value, or raise StopIteration
- |
- | ----------------------------------------------------------------------
- | Data and other attributes defined here:
- |
- | __new__ = <built-in method __new__ of type object>
- | T.__new__(S, ...) -> a new object with type S, a subtype of T
0 0
- python enumerate() 使用
- python enumerate的使用
- Python 中enumerate的使用
- python enumerate
- enumerate python
- python enumerate
- Python-enumerate
- Python Enumerate
- Python - enumerate
- python enumerate()
- python:enumerate
- Python enumerate
- python-enumerate()
- python: enumerate
- python enumerate
- python enumerate
- enumerate python
- Python的enumerate 枚举函数如何使用?
- PickView实现三级联动
- HTML5的menu菜单标签
- Android调试,解放你的数据线
- Log4j入门详解
- Android低阶 【chapter-7】GirdView和ListView常用的东西
- python enumerate() 使用
- LeetCode #315 Count of Smaller Numbers After Self
- Matlab读取带有地理信息的图像
- Android开发笔记—Http通信的基础使用
- c#中XmlTextReader读取xml
- python 安装配置、代码打包发布记录
- Hackerrank Coprime Power Sum
- 康托展开及其逆运算 详解
- Unity&Shader基础篇-“Hello Cg”