Nested if statement में जब एक if block के अन्दर दूसरा if block लगाया जाता है उसे ही nested if कहते हैं। और अच्छे से समझें, nested if statement में हम if के अन्दर if condition check करते हैं means पहले हम if condition check करेंगे अगर वो true है तो next if पे जायेगा फिर अगले वाले if को check करेगा। एक उदाहरण से समझें जैसे हम अपनी gmail पर Login कराते हैं तो वहाँ पर पहले वो हमसे हमारी ID पूछता है अगर ID ठीक है तब ही वो हमको password वाले option को show करता है।
Syntax: if expression : if expression : statement(s) else expression : statement(s) else: statement(s)
Example:
win = 30
user = int(input("Enter The Number between 1 to 50: "))
if user == win:
print("You Are Win")
else: # nested if else
if user<win:
print("Too Low")
else:
print("Too High")
Output:
Enter The Number between 1 to 50: 30
You Are Win
nested if statement को पढ़ने के बाद अन्य प्रकार के control statements नीचे दिये हुये हैं।
इन्हें भी देखें।
Python Programs के लिये यहाँ click करें।