PYTHON IF ELSE STATEMENT IN HINDI

Python me Condition checkers

Dusre languages me jaise – for loop, while loop, if, elif ka statement ka concept hota hai waise hi kuch condition checkers python me bhi available hote hain. To hum If Else ke conditions aur usse associated examples ko dekhte huye aage badenge.

Python If Else with Logical Operators

Logical Operators : 
==“, “<=“, “>=” ,”<“, “>“, “!=

If Example : 
x = 100
y = 100
if x == y:
    print(“x is equal to y”)

If Else Example : 
s = 200
t = 100
if s < t:
    print(“s is smaller than to t”)
else:
    print(“s is greater than t”)

elif Example : 
s = 100
t = 100
if s < t:
    print(“s is smaller than to t”)
elif s>t:
    print(“s is greater than t”)
else:
    print(“s is equal to t”)

Upar diye gaye sare example me aap ache se samajh payenge ki “if”, “elif” aur “else” kaise kam karte hain. Dhyan dene wali baat yah hai ki har ek statement me 2 baten common hai… Pahli, har ek statement ke baad (:) colon ka use hai aur Dusri, har ek statement ke baad next line indentation se shuru hai. Indentation means space jo keyboard ke 4 times ya fir 1 tab ke equal hota hai.

Agar aap python related tools like idle, Pycharm, VSCode, Notepad++, Jupyter etc, inme se koi bhi tool use kar rahe honge to aap dekhenge ki jaise hi aapne condition aur colon (:) lagakar enter button press kiya waise hi next line automatically indentation create kar dega. Lekin agar aisa nhi hota to aap ise jarur yaad rakhiyega.

Ek se jyada condition ko kaise handle karen?

x= 300
y= 93
z = 600
if x > y and z > x:
  print(“Output is True, because both conditions are true”)

x= 300
y = 600
z= 93
if x > y or z < x:
  print(“Output is True, because one condition is true”)

Python me If Else Nesting

Python me If Else ki Nesting same usi tarah hoti hai jaise dusre programming languages me hota hai,  Syntax ka difference ise easy bana deta hai kyuki isme opening aur closing braces ka concept nhi hai, sirf proper Indentation ka khyal rakhna hota hai.

a = 71
if a> 50:
 print(“More than 50,”)    #first indentation starts
      if a > 60:                          #inner loop or nested loop              print(“More than 60 Again”)   #indentation again 
      else:
          print(“but less than 80”)

Python me Pass statement ka concept

Python me pass statement ka unique role hai. Suppose aap if condition de rahe hain lekin aap if statement ke through kuch output nhi chahte hain to uske andar simply pass statement mention kar dijiye. Dhyan dene wali yah hai ki agar aap if statement blank rahne dege to wah error generate karega.

x = 71
y = 56

if y > x:
    pass