Home >> Python Tutorial >> Conditional Statements
Edit Template
Edit Template

Conditional Statements in Python in Hindi

What is Conditional Statements in python in Hindi

python में  decision making के लिए If-else conditional statement का use करते हैं, यह  specific conditions के  basis पर  code के different block को execute करते हैं, if-else का use करके हम program के flow को dynamically control कर सकते हैं.

How if-else work

What is If Statement in Hindi

यह condition को check करता है अगर condition true हुई तो if block execute हो जाता है अगर condition true नहीं हुई तो if block का execution नहीं होता है

🐍
if.py
Copy to clipboard
num = 10

if num > 5:
    print("Number is greater than 5")
else:
    print("Number is 5 or less")
    
# Output: Number is greater than 5

What is Else Statement in Hindi

अगर if condition false होती है तो else block का execution होता है.

इसे एक Example se समझते हैं

🐍
else.py
Copy to clipboard
num = 5

if num > 5:
    print("Number is greater than 5")
else:
    print("Number is 5 or less")
    
# Output: Number is  5 or less

What is Elif Statement in Hindi

python में multiple condition को  check करने के लिए elif statement का  use करते हैं जब एक से ज्यादा  conditions को sequencely check करना होता है तो इसका use किया जाता है

How elif works : 

इसका  use  if and else के बीच में किया जाता है हम अपने जरूरत के हिसाब से  multiple elif का Use करते हैं अगर if condition false हो जाती है तो  elif block का execution होता है अगर हमने अपने program में एक से ज्यादा elif का use किया है तो जो condition सही होगा उस elif block का execution होगा

इसे एक example के through समझते हैं : 

🐍
elif.py
Copy to clipboard
num = 5

if num > 5:
    print("Number is greater than 5")
else:marks = 75

if marks >= 90:
    print("Grade: A")
elif marks >= 75:
    print("Grade: B")
elif marks >= 50:
    print("Grade: C")
else:
    print("Grade: F")

# Output: Grade: B
    print("Number is 5 or less")
    
# Output: Number is  5 or less

What is Nested if-else in Hindi

जब हम किसी if condition के अंदर भी कोई condition check  Karte Hain तो इसे nested if else  कहते हैं

🐍
nested if-else.py
Copy to clipboard
age = 20
has_id = True

if age >= 18:
    if has_id:
        print("You can vote")
    else:
        print("You need an ID to vote")
else:
    print("You are too young to vote")

# Output: You can vote

What is Ternary Operator in Hindi

अगर python में हम conditional expression को एक लाइन में लिखने चाहे तो Ternary operator का use करना होता है इसमें value और condition और statement एक ही लाइन में लिख सकते हैं जैसा की syntax में दिया गया है

आइए इसे एक example की  help समझते हैं

🐍
ternary.py
Copy to clipboard
num = 10
result = "Even" if num % 2 == 0 else "Odd"
print(result)

# Output: Even

उम्मीद करते है कि आपको conditional statements in python अच्छे समझ मे आ गया होगा । अपने learning को continue रखने के लिए next button पर click करे,

Add a comment...

  • All Posts
  • Artificial Intelligence
  • Computer Fundamentals
  • Computer Networks
  • Data Analytics
  • Data Science
  • DBMS
  • Deep Learning
  • Digital Fundamentals
  • DSA with Python
  • Excel
  • Exercise
  • Git & Github
  • Machine Learning
  • Matplotlib
  • Natural Language Processing
  • NumPy
  • Operating System
  • Pandas-s
  • Power BI
  • Python Tutorial
  • Scikit-learn
  • Seaborn
  • SQL & MySQL
Python Function

Table of Contents All Chapters 1. Python Function 2. Define Function 3. Function Arguments 4. Function Parameters 5. Local and...

Python Dictionary

Table of Contents All Chapters 1. Python Dictionary 2. Access Dictionary items 3. Change Dictionary items 4. Add items in...

Python Set

Table of Contents All Chapters 1. Python Set 2. Iterate Set items 3. Set Methods      3.1. Add items...

Python Tuple

Table of Contents All Chapters 1. Python Tuple 2. Access Tuple Items 3. Update Tuple 4. Iterate Tuple Items 5....

Python List

Table of Contents All Chapters 1. Python List 2. Nested List 3. Range List 4. List Indexing 5. list Methods...

Python String

Table of Contents All Chapters 1. Python String 2. String Indexing 3. String Slicing 4. String Concatenation 5. String Formatting...

Python Loops

Table of Contents All Chapters 1. Python Loops 2. While Loop      2.1. Nested While Loop 3. For Loop...

Edit Template
Scroll to Top