CBSE Class 11: Python List 12

Iterating Through a List / Traversing a List

We can traverse a list using for loop and while loop

#using for loop
n=[1,2,3,4,5]
for i in n:
	print(i)

Output:

1
2
3
4
5

#using while loop
n=[1,2,3,4,5]
i=0
while i<len(n):
	print(n[i])
	i+=1

Output:

1
2
3
4
5

n=["amit","sumit","kapil","mukesh"]
for i in n:
    print(i)

Output:

amit
sumit
kapil
mukesh