Python Iteration - For loop, While loop
Today we are going to learn what are Python
Iteration and python for loop, python loop while, python loop list,
python iterator next and python group iteration.
After reading this post we will know-:
- How are iteration in Python works?
- What are iterator and iteration ?
- What is iterator Protocol?
- What is lazy evaluation ?
What is Iteration in Python?
A kind of a repetition is called Iteration.
For
example-:
Usually in our daily life we repeat some task for example we pay electricity bill every month.
Same as a silkworm lays eggs and turns into caterpillar, becomes a pupa, matures as a silk worm and lays eggs again and again cycle starts.
Same like this in Python we use iteration which is a kind of a repetition we perform.
This repetition in
Python can be done using looping.
To Understand it more let's check a example.
If you want to print your name one time so you use this statement.
print ( " Name " )
If you want to print
your name 10 times you use this statement
print ( " Name " )
print ( " Name " )
print ( " Name " )
print ( " Name " )
print ( " Name " )
print ( " Name " )
print ( " Name " )
print ( " Name " )
print ( " Name " )
print ( " Name " )
But what if you want to
print your name 100 times or l0000 times.
Here looping statements
comes into play.
What is Looping?
We use looping statement
to perform a task again and again until the condition is wrong.
There are two types of
loop statement in Python which are
- For loop
- While loop
While loops-:
While loops are also
called identified loops because statements are executed until logical condition
remains true.
click on the link to go to while loop -:
for example -:
n=5
while
n > 0:
print(n)
n = n-1
Output-:
5
4
3
2
1
For loop-:
For Loops are called definite loops because statements are executed for definite number of times.
click on the link to go to while loop -:
for example-:
for i in range ( 5, 0,-1):
print(i)
Output-:
5
4
3
2
1
For any problem comment
below or contact us.
Social Plugin