Python Lists basically serve the purpose of arrays and store data/elements in it.
Python列表基本上是用于数组的目的,并在其中存储数据/元素。
Lists can be traversed through a number of ways.
可以通过多种方式遍历列表。
在Python中迭代列表的方法 (Ways to iterate List in Python)
- By using for Loop 通过使用for循环
- By using while Loop 通过使用while循环
- By using List Comprehension 通过使用列表理解
- By using for loop and range() function 通过使用for循环和range()函数
- By using NumPy 通过使用NumPy
- By using enumerate() function 通过使用enumerate()函数
1.使用for循环迭代列表 (1. Iterating List using for Loop)
Python for loop can be used to iterate through the List.
Python for loop可用于遍历List。
Example:
例:
input_list = [10, "Safa", 15,