Articles → Python → Loops In Python

Loops In Python






What Are Loops?





Types Of Loops




  1. While loop
  2. For loop



While Loop




While condition:
      Statements to be executed




x  = 0

while x < 10:
    print ("Value of x is ", x)
    x = x + 1




Picture showing the output of the while loop in python




x  = 0

while x < 10:
    print ("Value of x is ", x)
    x = x + 1
else:
    print("Value of x is equal to 10")




Picture showing the output of the while loop in python



For Loop




for  object_variable in collection:
            Statements to be executed.




name = "Karan"

for character in name:
    print (character)




Picture showing the output of the for loop in python




classmates = ["Karan","sumit","amit"]

for name in classmates:
    print (name)




Picture showing the output of the for loop through collection in python



Posted By  -  Karan Gupta
 
Posted On  -  Monday, February 18, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250