Edit Template
Edit Template
Edit Template

Conditional Statements in Python

What is conditional Statements in python

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

If Statement

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

num = 10

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

Else Statement

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

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

num = 5

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

Elif Statement

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 समझते हैं : 

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

Nested if-else

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

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

Ternary Operator

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

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

num = 10
result = "Even" if num % 2 == 0 else "Odd"
print(result)

# Output: Even

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

Some important questions in this tutorial

What is Conditional Statements in Python, Python me Conditional Statements kya hota hai.

Click here www.w3schools.com/python  to learn python in english

Add a comment...

Your email address will not be published. Required fields are marked *

  • 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 List

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...

Python String

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...

Python Loops

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...

Conditional Statements

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...

Python Operators

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...

Python Data Type

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...

Scikit-learn

Scikit-learn Tutorial Scikit-learn Hamburger Toggle Menu Edit Template Scikit learn What is Scikit-learn Scikit learn एक python library है जिसका...

Pandas

Pandas Tutorial Pandas Hamburger Toggle Menu Edit Template Pandas What is Pandas pandas  एक python library है, जिसका use हम...

NumPy

NumPy Tutorial NumPy Hamburger Toggle Menu Edit Template NumPy What is NumPy matplotlib का use हम data visualization के लिए...

Edit Template
Scroll to Top