Home > Notes > python

Python Loops

python

Python Variable
Python Conditional statement
Python loops
Python List
Python Tuple
Python String
Python Set
Python Dictionary
Python Functions
Python Exceptions
Python File Operation
Python Map
Python Lambda
Python Filter
Python OOPS

Python Loops

Python For loop with one parameter

in this example u , will see the giving one value in the range

for i in range(10):
 print(i)

Python For loop with two parameter

in this example u , will see the giving two parameter in the range. where the first parameter will be treated as starting limit and second parameter is treated as ending limit

for i in range(10,20):
 print(i)

Python For loop with Three parameter

in this example u , will see the giving Three parameter in the range. where the first parameter will be treated as starting limit and second parameter is treated as ending limit and last parameter is treated as interval.

for i in range(10,20,2):
 print(i)

Python For loop with decending order

in the below example u will see the example for loop with decending order in python.

for i in range(40,20,-2):
 print(i)

Python For loop nested

A nested loop is a loop inside a loop. The “inner loop” will be executed one time for each iteration of the “outer loop”:

for i in range(1,5):
 for j in range(7,10):
  print("i value is " , i)
  print("j value is " , j)
print("\n")
print("\n")

While loop

With the while loop we can execute a set of statements as long as a condition is true.

i = 1
while i < 6:
 print(i)
 i+=1