Python 3 Tutorial for beginners in Hindi-Chapter 15(Conditional control statements)
Updated: Nov 10, 2020
Conditional statements क्या है ?
Conditional statement तार्किक अभिव्यक्तियाँ(logical expressions) हैं जो result के रूप में सही या गलत return करते हैं ।
एक program में statements के flow को नियंत्रित करने के लिए conditional statements का उपयोग किया जाता है।
Python में 3 प्रकार के conditional statements है।
if
if else
if elif else
1.if
'if ' is one-way branching, मतलब यह केवल उन conditions के लिए काम करेगा जो true return करेंगे।
Syntax
if condition:
statement 1
statement 2
other statements
Example
Write a program to check the biggest or same among 2 numbers.
no1 =10
no2 =20
if no1 > no2:
print(no1,"is big")
if no1 < no2:
print(no2,"is big")
if no1 = no2:
print("Both are same")
Output: 20 is big
2.if else
'if else' is 2-way branching. मतलब ये true और false दोनों conditions के लिए काम करता है।
Syntax
if condition:
statement 1
statement 2
else:
statement 3
statement 4
other statements
Example
Write a program to check whether 2 numbers are equal or not
no1 = 10
no2 = 20
if no1 = no2:
print("Both are same")
else:
print("Numbers are not equal")
Output: Numbers are not equal
Nested if else
हम एक 'if else' condition के अंदर multiple 'if else' का इस्तमाल कर सकते हैं।
Example
no1 = 10
no2 = 20
if no1 > no2:
print(no1,"is big")
else:
if no1 < no2:
print(no2,"is big")
else:
print("Both are same")
Output: 20 is big
3.if elif else
elif stands for else if.
एक if else के अंदर multiple elif रह सकता है।
Syntax
if condition:
statement 1
statement 2
elif condition:
statement 3
statement 4
else:
statement 5
statement 6
other statements
Example
Write a program to check the big number
no1 = 10
no2 = 20
if no1 > no2:
print(no1,"is big")
elif no1 < no2:
print(no2,"is big")
else:
print("Both are same")
Output: 20 is big
इस चैप्टर में हमने python conditional statements के सीखा। अगले चैप्टर में हम Python loops के बारेमे जानेंगे।
अगर आपको chapterwise notes chhiye तो निचे कमेंट करे।