How many loops Python have?What are those loops?
Do you know how many loops Python support?
Do you have similar website/ Product?
Show in this page just for only
$2 (for a month)
0/60
0/180
Python language has only two loops:
E.g:
In above example it will print until cal is less than 10.
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 .
E.g:
my_result= [1,2,3,4]
for i in my_result: print(i) |
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): print(i) |
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: print(count) cal += 1 |
CONTINUE READING
Python Language
Ayesha
Tech writer at newsandstory