在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怎么念

Python os.chmod()方法是什么?它能起到什么作用?

Python中list函数怎么用

Python中reverse、sort、sorted三个列表排序使用方法详解

Python如何求平均数

ubuntu能卸载Python

ansible作为Python模块库使用的方法

Python中线程与进程的区别与优劣

Python如何实现颜色

Python学什么方向

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




打赏

取消

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

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

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

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

评论

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