Enter your email id to get regular update free
Your Email

How many loops Python have?What are those loops?

Do you know how many loops Python support?

Python  language has only two loops:
1.for loop 
2.while loop
For loop
 Syntax of For loop:
for i in iterating_object:
# show some output
All the statements inside "for"  and "while" loop should be indented to the same number of spaces. Otherwise it will throw the SyntaxError .
my_result= [1,2,3,4]
 for i in my_result:
 range(a,b) Function
This range(a, b) functions returns sequence of integers from a , a + 1 , a+ 2 …. , b - 2 , b - 1 . 
for i in range(5, 20):

While loop
While loop keeps executing statements inside it until condition becomes false. 
After each iteration condition is checked and if its True then once again statements inside the while loop will be executed.
Syntax of While loop is :
while condition:
 # body 
cal = 0
 while cal < 10:
 cal += 1
In above example it will print until cal is less than 10.
Python Language
Tech writer at newsandstory
Total 490 views