1list = [1, 3, 5, 7, 9]
2
3# with index
4for index, item in enumerate(list):
5 print (item, " at index ", index)
6
7# without index
8for item in list:
9 print(item)
1# Iterate through a string using a for loop
2name="Nagendra"
3for letter in name:
4 print(letter)
5
6# Iterate through a string using a for loop
7index = 0
8while index<len(name):
9 print(index)
10 index += 1
11#Iterate through a list of strings using a for loop
12list_names = ['Nagendra','Nitesh','Sathya']
13for name in list_names:
14 print(name)
15
16#Iterate through a string using a while loop
17list_names = ['Nagendra','Nitesh','Sathya']
18index = 0
19while index<len(list_names):
20 print(list_names[i])
21 index += 1
22
1# Python list
2my_list = [1, 2, 3]
3
4# Python automatically create an item for you in the for loop
5for item in my_list:
6 print(item)
7
8