今天看源码的时候看到这样一段:
for i, score in enumerate(top_scores):不知道是什么意思就查了一下手册,手册是这么说的:
enumerate()函数可以同时取出列表(元组)中的成员的索引和内容
也就是说采用原始的办法,上面的代码应该这么的写:
for i in range(len(top_scores)):
index = i
item = top_scores[i]这样看应该就一目了然enumerate()的用法了
本文详细解析Python中enumerate()函数的用法,并通过实例展示如何在遍历列表时同时获取索引和元素,提升代码效率和可读性。
今天看源码的时候看到这样一段:
for i, score in enumerate(top_scores):enumerate()函数可以同时取出列表(元组)中的成员的索引和内容
也就是说采用原始的办法,上面的代码应该这么的写:
for i in range(len(top_scores)):
index = i
item = top_scores[i]这样看应该就一目了然enumerate()的用法了
642
1757
5万+
378

被折叠的 条评论
为什么被折叠?