通过本文主要向大家介绍了python enumerate,python enumerate函数,python中enumerate,python3 enumerate,enumerate等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
其他语言中,比如C#,我们通常遍历数组是的方法是:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
for (int i = 0; i < list.Length; i++)


{
//todo with list[i]
}</div>
在Python中,我们习惯这样遍历:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
for item in sequence:
process(item)</div>
这样遍历取不到item的序号i,所有就有了下面的遍历方法:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
for index in range(len(sequence)):
process(sequence[index])</div>
其实,如果你了解内置的enumerate函数,还可以这样写:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
for index, item in enumerate(sequence):
process(index, item)</div>
</div>
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
for (int i = 0; i < list.Length; i++)

{
//todo with list[i]
}</div>在Python中,我们习惯这样遍历:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
for item in sequence:
process(item)</div>这样遍历取不到item的序号i,所有就有了下面的遍历方法:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
for index in range(len(sequence)):
process(sequence[index])</div>其实,如果你了解内置的enumerate函数,还可以这样写:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
for index, item in enumerate(sequence):
process(index, item)</div>
</div>

