Conditional statements और operators

डेवलपर्स के लिए Python परिचय

Jasmin Ludolf

Senior Data Science Content Developer

Booleans

# Boolean variable
the_truth = True
print(the_truth)
True
  • तुलना करने के लिए उपयोग होते हैं
डेवलपर्स के लिए Python परिचय

Operators

  • Comparison operators

    • प्रतीक या प्रतीकों के संयोजन
    • मानों की तुलना करने के लिए उपयोग
  • जाँचें कि दो चीजें बराबर हैं या नहीं

    • ==
डेवलपर्स के लिए Python परिचय

समानता की जाँच

# Compare if 2 is equal to 3
2 == 3
False
# Check that 2 is not equal to 3
2 != 3
True
  • आम उपयोग: लॉगिन विवरण जाँचना
डेवलपर्स के लिए Python परिचय

संख्यात्मक तुलना ऑपरेटर्स

# Is 5 less than 7?
5 < 7
True
# Is 5 less than or equal to 7?
5 <= 7
True
# Is 5 greater than 7?
5 > 7
False
# Is 5 greater or equal to 7?
5 >= 7
False
डेवलपर्स के लिए Python परिचय

अन्य तुलना

# Is James greater than Brian
"James" > "Brian"
True
  • स्ट्रिंग्स का मूल्यांकन वर्णानुक्रम में होता है
डेवलपर्स के लिए Python परिचय

Conditional statements

  • अगर if शर्त पूरी हो, तो क्रिया करें, वरना छोड़ दें
# Check pasta quantities
required_quantity = 500
pasta_quantity = 200


# Compare pasta quantities if pasta_quantity >= required_quantity
डेवलपर्स के लिए Python परिचय

Conditional statements

  • अगर if शर्त पूरी हो, तो क्रिया करें, वरना छोड़ दें
# Check pasta quantities
required_quantity = 500
pasta_quantity = 200


# Compare pasta quantities if pasta_quantity >= required_quantity:
डेवलपर्स के लिए Python परिचय

Conditional statements

  • अगर if शर्त पूरी हो, तो क्रिया करें, वरना छोड़ दें
# Check pasta quantities
required_quantity = 500
pasta_quantity = 200


# Compare pasta quantities if pasta_quantity >= required_quantity:
print("You have enough pasta!")
डेवलपर्स के लिए Python परिचय

इंडेंटेशन

# Check pasta quantities
required_quantity = 500
pasta_quantity = 200


# Compare pasta quantities if pasta_quantity >= required_quantity:
print("You have enough pasta!") # This line is not indented
    print("You have enough pasta!")
    ^
IndentationError: expected an indented block
डेवलपर्स के लिए Python परिचय

Elif statement

# Check pasta quantities
required_quantity = 500
pasta_quantity = 200

# Compare pasta quantities if pasta_quantity >= required_quantity:
print("You have enough pasta!")
elif pasta_quantity >= 300: print("Nearly enough pasta. Try a smaller portion.")
  • आप जितने चाहें उतने elif keywords उपयोग कर सकते हैं!
डेवलपर्स के लिए Python परिचय

Else statement

# Check pasta quantities
required_quantity = 500
pasta_quantity = 200

# Compare pasta quantities if pasta_quantity >= required_quantity:
print("You have enough pasta!")
elif pasta_quantity >= 300: print("Nearly enough pasta. Try a smaller portion.")
# Otherwise... else: print("Not enough pasta.")
Not enough pasta.
डेवलपर्स के लिए Python परिचय

Comparison operators cheat sheet

Operator Function
== Equal to
!= Not equal to
> More than
>= More than or equal to
< Less than
<= Less than or equal to
Keyword Function Use
if If condition is met First in the workflow
elif Else check if condition is met After if
else Else perform this action After elif
डेवलपर्स के लिए Python परिचय

अभ्यास करते हैं!

डेवलपर्स के लिए Python परिचय

Preparing Video For Download...