how many loop are there in python program
Answers
You can loop a function infinitely in python.
Well, for a beginner level, I would say there are 2 loops which are very important and are very frequently used.
1) If- else -
This if else is the most common loop used in python. To explain this loop, I will be using a real life example. The scenario is you standing in a rain for all the 2 loops. For the if-else loop, its like:
if it is raining, then get the umbrella. Else, do not bring the umbrella.
If you would write this in python, it would look like:
if it is raining:
bring the umbrella
else:
leave the umbrella
The indentation is very crucial during the loops. Indentation is the spaces. For each basic criteria, there are 4 spaces.
2) While loop -
While loop is frequently used too but not as much as if-else loop. To get this into real life example. Its like, while it is raining, keep holding the umbrella.
If we would write this in python, it would look like:
raining = True
while raining:
hold the umbrella
The 'True' I used is a boolean operator which takes just 2 inputs, True and False.
These are the common loops.
Hope I had helped! :)