how to loop through a list in python code example
Example 1: python loop through list
list = [1, 3, 6, 9, 12]
for i in list:
print(i)
Example 2: how to loop over list
list = [1, 2, 3, 4, 5, 6]
for item in list:
print(item)
for index in range(len(list)-1):
print(list[index])
for index, value in enumerate(list):
print(value)
Example 3: iterate over list of strings python
name="Nagendra"
for letter in name:
print(letter)
index = 0
while index<len(name):
print(index)
index += 1
list_names = ['Nagendra','Nitesh','Sathya']
for name in list_names:
print(name)
list_names = ['Nagendra','Nitesh','Sathya']
index = 0
while index<len(list_names):
print(list_names[i])
index += 1
Example 4: list loop python
list = [1, 3, 5, 7, 9]
for index, item in enumerate(list):
print (item, " at index ", index)
for item in list:
print(item)
Example 5: python iterate list
lst = [10, 50, 75, 83, 98, 84, 32]
for x in range(len(lst)):
print(lst[x])
Example 6: how to iterate over a list in python
my_list = [1, 2, 3]
for item in my_list:
print(item)