if-else Statement in Python in Hindi

Arpit Nageshwar
⏰ 3 min read

if-else Statement in Python in Hindi – if-else Statement Kya Hai?

Table of Contents

Syntax of if-else Statement in Hindi – if-else का Syntax

  • Python में जब भी किसी condition के आधार पर दो अलग-अलग कामों में से कोई एक काम करना हो, तब if-else Statement का इस्तेमाल किया जाता है, यह Decision Based Processing का सबसे basic aur सबसे ज्यादा इस्तेमाल होने वाला statement है।

  • Simple भाषा में कहें तो if-else Statement यह check करता है कि दी गई condition True है या False, अगर condition True निकलती है तो if वाला block execute होता है, वरना else वाला block execute होता है।

  • Python में if-else लिखने का basic syntax कुछ इस तरह होता है:

if condition:
    # Statement(s) jo True hone par chalenge
else:
    # Statement(s) jo False hone par chalenge
  • ध्यान देने वाली सबसे जरूरी बात यह है कि Python में if और else की line के आखिर में हमेशा colon : लगाया जाता है, और उसके अंदर आने वाले statements को हमेशा indentation (spacing) की मदद से अलग रखा जाता है।

  • Python किसी भी curly braces { } का इस्तेमाल नहीं करता, बल्कि indentation ही यह decide करती है कि कौन सा statement किस block का हिस्सा है, इसलिए indentation में हुई छोटी सी गलती भी पूरे program को गलत बना सकती है।

  • एक बात और ध्यान रखने वाली है कि else के साथ कोई condition नहीं लिखी जाती, क्योंकि जब भी if की condition False होगी, तभी else वाला block automatically चल जाएगा।

if-elif-else Ka Extended Syntax (Bonus):
अगर एक से ज्यादा conditions check करनी हों, तो elif keyword की मदद से syntax को आगे बढ़ाया जा सकता है:

if condition1:
    # Statement(s)
elif condition2:
    # Statement(s)
else:
    # Statement(s)

Flowchart of if-else Statement in Hindi – if-else का Flowchart

if-else Statement Flowchart Start Condition True ya False? True if Block Execute hoga False else Block Execute hoga Stop In dono blocks (if/else) mein se hamesha sirf ek hi chalega
  • Flowchart में Decision Symbol (Diamond) से हमेशा दो अलग-अलग arrows निकलते हैं – एक True की तरफ और एक False की तरफ, यही if-else की असली पहचान है।

  • True वाले रास्ते पर if का block execute होता है, और False वाले रास्ते पर else का block execute होता है, लेकिन एक बार में सिर्फ एक ही block चल सकता है, दोनों कभी एक साथ execute नहीं होते।

  • दोनों रास्ते (True और False) आखिर में वापस एक ही जगह मिल जाते हैं, और उसके बाद program का बाकी हिस्सा normal तरीके से आगे बढ़ता रहता है, यही वजह है कि if-else को एक Single Entry, Single Exit structure माना जाता है।

Example Programs in Python in Hindi – if-else के उदाहरण

Example 1: Even ya Odd Number Check Karna

num = int(input("Number enter karo: "))

if num % 2 == 0:
    print("Number Even hai")
else:
    print("Number Odd hai")

Example 2: Sabse Bada Number Batana (Do Numbers Ke Beech)

a = int(input("Pehla number enter karo: "))
b = int(input("Dusra number enter karo: "))

if a > b:
    print(a, "sabse bada hai")
else:
    print(b, "sabse bada hai")

Example 3: Voting Eligibility Check Karna

age = int(input("Apni age enter karo: "))

if age >= 18:
    print("Aap vote de sakte hain")
else:
    print("Aap abhi vote nahi de sakte")

Example 4: Positive ya Negative Number Check Karna

num = int(input("Number enter karo: "))

if num >= 0:
    print("Number Positive (ya Zero) hai")
else:
    print("Number Negative hai")

Example 5: Login Password Check Karna (Real-World Style)

correct_password = "python123"
entered_password = input("Apna password enter karo: ")

if entered_password == correct_password:
    print("Login Successful!")
else:
    print("Galat Password, dobara try karo")

इन सभी examples में ध्यान दीजिए कि हर बार सिर्फ एक ही condition check की जा रही है, और उसके True या False होने के हिसाब से सिर्फ एक ही message print हो रहा है, यही if-else Statement का सबसे बुनियादी और सबसे ज्यादा इस्तेमाल होने वाला pattern है।

Frequently Asked Questions (FAQ) – if-else Statement in Python in Hindi

वह statement जो किसी condition को check करके, उसके True होने पर एक block और False होने पर दूसरा block execute करता है, उसे if-else Statement कहते हैं।

Python curly braces { } की जगह indentation (spacing) का इस्तेमाल करता है, ताकि यह पता चल सके कि कौन सा statement if या else block का हिस्सा है।

Nahi, else ke saath koi condition nahi likhi ja sakti, kyunki jab bhi if ki condition False hogi, else block automatically execute ho jata hai, agar aur conditions check karni ho to elif ka use kiya jata hai।

if-else ke flowchart mein condition check karne ke liye Diamond (Decision) symbol use hota hai, jisse True aur False ke liye alag-alag arrows nikalte hain।

Nahi, ek particular run mein if aur else mein se sirf ek hi block execute hoga, kyunki condition ya to True hogi ya False, dono ek saath kabhi nahi ho sakti।

Arpit Nageshwar

✍️ Arpit Nageshwar

Post-graduated | Web Developer | +3 yr Experience | IIT Kharagpur Certified