本文摘自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)
|
运行结果:
二、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》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 在Python中遍历列表的方法有哪些