Python if else In Hindi | Python Programming in Hindi

Python if else In Hindi In Python Programming

Python if else In Hindi: Python ek aisi programming language hai jo seekhne aur use karne mein bahut aasan hai. Is article mein hum Python ke if else statements ko Hindi mein samjhenge. Python mein if else ka use condition ke according alag-alag code blocks ko run karne ke liye kiya jata hai. Yani jab humein kisi condition ke true hone par kuch alag code run karna ho aur condition false hone par kuch aur, tab hum if else statements ka use karte hain.

Python if else In Hindi: Python Programming in Hindi
Python if else In Hindi: Python Programming in Hindi

Python Programming in Hindi

Python Programming in Hindi: Python ek bahut hi flexible aur powerful programming language hai. Ismein agar aap if else statements ko sahi tareeke se samajh lete hain, toh aapke programming skills mein kaafi sudhaar aayega. Upar diye gaye examples ko follow karke aap bhi Python mein if else ka use kar sakte hain.

यह भी पढ़ें: 250+ Free Python Projects with Source Code: From Beginner to Advanced

Yadi aap Python programming mein naye hain, toh ghabraayein nahi. Python ek aisi bhasha hai jo beginners ke liye bhi accessible hai. Ismein concepts ko samajhna aur code likhna kaafi aasan hai.

Python if else Syntax

Python mein if else statement ka basic syntax kuch is tarah hota hai:

if condition:
    # yahan wo code likhen jo aap run karna chahte hain
else:
    # yahan wo code likhen jo aap run karna chahte hain

Python ek case-sensitive language hai, isliye predefined keywords ko sahi tarike se likhna zaroori hai. Matlab, aapko "if" aur "else" hi likhna hoga, "If" ya "Else" nahi.

Python if else Example

Ek chhota sa example dekhte hain:

age = 18
if age >= 18:
    print("You are eligible to vote")
else:
    print("You are not eligible to vote")

Is example mein, agar age 18 ya usse zyada hai to "You are eligible to vote" print hoga, warna "You are not eligible to vote" print hoga.

Python mein Conditional Values

Python mein conditions ko alag-alag tarikon se likha ja sakta hai. Kuch common values jo condition mein use hoti hain aur unka true ya false result ye hain:

Chaliye kuch examples dekhte hain:

if -4:
    print('-4:', True)
else:
    print(False)

if 5:
    print('5:', True)
else:
    print(False)

if 0:
    print(True)
else:
    print('0:', False)

if '    ':
    print('empty string with spaces:', True)
else:
    print(False)

if "":
    print(True)
else:
    print('empty string without space:', False)

if 'hi':
    print('hi:', True)
else:
    print(False)

In sab examples ka output kuch is tarah se hoga:

-4: True
5: True
0: False
empty string with spaces: True
empty string without space: False
hi: True

Python Short Hand if / else

Agar aapko if else statement ko ek hi line mein likhna hai to short hand if/else ka use kar sakte hain. Dekhte hain kaise:

age = 89
if age >= 18: print("You are eligible to vote")

Yahan, condition true hone par "You are eligible to vote" print hoga. Isi tarah, short hand if else statement kuch is tarah se likha ja sakta hai:

age = 12
print("You are eligible to vote") if age >= 18 else print("You are not eligible to vote")

Yahan condition false hone par "You are not eligible to vote" print hoga.

Python if elif

Agar aapko ek se zyada conditions check karni hain to Python mein if elif statements ka use karte hain. Jaise:

marks = 86
if marks >= 90:
    print('Grade: A+')
elif marks >= 80:
    print('Grade: A')
elif marks >= 70:
    print('Grade: B')
else:
    print('Grade: C')

Is example ka output hoga: "Grade: A"

Python Programming in Hindi: Advanced if elif else Example

Ek aur example dekhte hain jahan multiple conditions ko check karte hain aur different outputs dete hain:

temperature = 35
if temperature > 40:
    print("It's too hot!")
elif temperature > 30:
    print("It's warm.")
elif temperature > 20:
    print("It's cool.")
else:
    print("It's cold.")

Yahan, temperature ke value ke hisaab se alag-alag messages print honge.

Python if else aur Loops ka Combination

Python mein aap if else statements ko loops ke sath bhi use kar sakte hain. Jaise:

numbers = [1, 2, 3, 4, 5]
for num in numbers:
    if num % 2 == 0:
        print(f"{num} is even")
    else:
        print(f"{num} is odd")

Is example mein, list ke har element ko check karte hain aur uske even ya odd hone par respective message print karte hain.

Python Ternary Operator

Python mein if else ko ternary operator ke form mein bhi likha ja sakta hai. Ye ek concise way hai conditional statements likhne ka. Example:

age = 22
status = "Eligible" if age >= 18 else "Not Eligible"
print(status)

Yahan, agar age 18 ya usse zyada hai to "Eligible" assign hoga, warna "Not Eligible".

Python if else In Hindi: Conclusion

Python mein if else statements ka use karke aap complex decision-making logic implement kar sakte hain. Is article Python if else In Hindi mein humne dekha kaise different conditions check ki ja sakti hain aur unke basis par alag-alag code blocks run kiye ja sakte hain. Python programming mein if else statements bahut hi important aur powerful tool hain jo aapke code ko zyada dynamic aur flexible banate hain.

Python mein if else statements ka use karna seekhna kisi bhi programmer ke liye zaroori hai. Yeh ek fundamental concept hai jo har programming language mein hota hai. Upar diye gaye examples aur explanation se aapko samajh aagayi hogi ki Python mein if else kaise kaam karta hai. Abhi se practice shuru karein aur apne programming skills ko aur bhi behtar banayein.

Is article Python if else In Hindi ke madhyam se humne if else, short hand if else, if elif aur inhe loops ke sath kaise use karein sab kuch detail mein dekha. Agar aap Python seekh rahe hain to in statements ko acche se samajhna aur practice karna bahut zaroori hai.

यह भी पढ़ें: Python Programming In Hindi | Python Tutorials In Hindi

और नया पुराने

संपर्क फ़ॉर्म