python用什么遍历list?

Python (212) 2023-05-16 12:05:36

在python中,遍历list使用for循环。python中的list对象是可迭代对象,所以可以直接用for循环遍历list中的每一个数据。

python中的list对象是可迭代的所以可以直接使用for循环遍历list中的所有数据。

ls=[1,2,3,4]

foriinls:
print(i)

结果是:

1
2
3
4

推荐课程:Sublime编辑器(Corey Schafer)

THE END

发表回复