Introduction of Python
Getting Started with Python
Syntax in Python
Comment in Python
Variables in Python
Data Types in Python
Numbers in Python
Castings in Python
Strings in Python
Boolean in Python
Operators in Python
List in Python
Tuples in Python
Sets in Python
Dictionary in Python
if Else Statement in Python
While Loop in Python
For Loop in Python
Functions in Python
Lamba Function in Python
Arrays in Python
Classes and Objects in Python
Inheritance in Python
Iterators in Python
Scope in Python
Modules in Python
Dates in Python
Math in Python
JSON in Python
RegEx in Python
Try and Except in Python
User Input in Python
String Formatting in Python
Python For Loop Overview
For loop kisi bhi programming language ka most important topic hai. Yah iteration ka work sequential ways me perform karta hai. Iteration means liye gaye conditions ke hisab se one by one execution ki process ko handle karna.
Aap iska use List, Sets, Tuple, Dictionary, Strings etc kai tarah ki conditions me kar sakte hain. Example se iska use samajhte hain.
#For List
countries = [“usa”, “india”, “russia”]
for a in countries:
print(a)
#For Dictionary
leader = {“usa”:”trump”, “india”:”modi”, “russia”:”putin”}
for x,y in leader.items():
print(“country : “+x, ” leader: “+y)
#For String
city = “Bangalore”
for x in city:
print(“x”)
For Loop ka range() function ke sath working
Range() function number sequence ko return karta hai. By default iski starting value ‘0’ hoti hai aur yah kisi bhi sequence ko +1 ke step me return karta hai. Agar aap chahe to iski starting value, end value aur step value change bhi kar sakte hain.
#Default Range() use
for y in range(9):
print(y)
#User defined Range
#start value = 2; end value=20; step=3
for y in range(2,20,3):
print(y)
For Loop ka Else ke sath use
#For Loop + Else
for y in range(9):
print(y)
else:
print(“Range Function done its job”)
For Loop aur Nested Loop ka Combination
#For Loop + Nested Loop
state = [“delhi”,”rajasthan”,”madhyapradesh”]
city= [“delhi”,“jaipur”,“bhopal”]
for x in state:
for y in city:
print(x+,” : “,+y)