For Loop
In python, loops are also used to iterate over any sequences like list , tuple , string , dictionary etc. It is possible for iterate multiple sequences at a same time and nested loops are also possible using multiple looks inside loops . For loop is most important loop and most of the people use it . In for loop first condition is checked and later code executes only if condition is true .
For Loop with Range:-
Here range start from 0 to 5 . loop will run 5 times and it will print 0 to 4.
for x in range(0,5):
print(x)
Output :-
0
1
2
3
4
Using Loop in List :-
alpha = ["a", "b", "c"]
for x in alpha:
print(x)
Output:-
a
b
c
Using Loop in String :-
var="babab"
for x in var:
print (x)
Output:-
b
a
b
a
b