在Python中遍历列表的方法有哪些


本文摘自php中文网,作者尚,侵删。

Python中遍历列表有以下几种方法:

一、for循环遍历

1

2

3

lists = ["m1", 1900, "m2", 2000]

for item in lists:

print(item)

1

2

3

4

lists = ["m1", 1900, "m2", 2000]

for item in lists:

item = 0;

print(lists)

运行结果:

1

['m1', 1900, 'm2', 2000]

二、while循环遍历:

1

2

3

4

5

lists = ["m1", 1900, "m2", 2000]

count = 0

while count < len(lists):

print(lists[count])

   count = count + 1

三、索引遍历:

阅读剩余部分

相关阅读 >>

Python基本语法

lintcode题目记录4

Python教程中的注释是什么

Python3如何使用pil

Python打开怎么运行

Python诞生于什么时候

Python什么意思中文翻译

怎么卸载Python3.5

Python安装后怎么用不了

Python语言公开发行版本诞生于哪年

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...