For loop in python with examples

For loop is used to iterate each element in the sequence.We can iterate elements in the list,tuple,dictionary,set and string.Similar like other programming languages,for is the keyword in python and we need to specified the range of elements to perform the iteration.

Example 1: Increment by 1 with range

EThe below for loop defined as for(x=1;x<5;x++) in C programming language)

Output:
1
2
3
4

Example 2:Increment by 2

Increment value given as 2 in the range function(x=0;x<8;x+=2)

Output:
1
3
5
7

Example 3: Increment by 1 from 0

Default increment is 1 in the range function(x=0;x<5;x++)

Output:
0
1
2
3
4

Example 4 : Looping through String

Output:
R
E
V
I
S
I
T
C
L
A
S
S

Example 5: Looping through list

Output:
REVISIT
CLASS
PYTHON