Python Relational Operators
In this page:
result = a == b # also !=, >, <, >=, <=
बराबरी और असमानता
== जाँचता है कि दो values बराबर हैं और != जाँचता है कि वे अलग हैं; दोनों हमेशा bool लौटाते हैं, और शुरुआती लोगों की आम गलती है वहाँ = (assignment) लिख देना जहाँ == (तुलना) चाहिए था।
उदाहरण: Equality and Inequality
print(5 == 5)
print(5 != 3)
बड़ा और छोटा
> और < दो values के परिमाण की तुलना करते हैं — संख्याएँ मान के आधार पर तुलनी जाती हैं, और नतीजा हमेशा True या False होता है, जो सीधे if statement की शर्त में इस्तेमाल के लिए तैयार है।
उदाहरण: Greater Than and Less Than
print(7 > 3)
print(2 < 1)
बड़ा-या-बराबर और छोटा-या-बराबर
>= और <= वैसे ही व्यवहार करते हैं जैसे > और <, पर बराबरी को भी शर्त पूरी करने वाला गिनते हैं, जो तब मायने रखता है जब कोई सीमा वाला value खुद वैध सीमा में शामिल होना चाहिए, जैसे "18 या उससे ज़्यादा" की आयु सीमा।
उदाहरण: Greater Than or Equal to and Less Than or Equal to
age = 18
print(age >= 18)
Strings की तुलना
Strings की तुलना lexicographically होती है, यानी हर character के अंतर्निहित code point के आधार पर character-दर-character — इसलिए "apple" < "banana" True है क्योंकि a b से पहले आता है, वही तर्क जो शब्दकोश वर्णानुक्रम के लिए इस्तेमाल करता है।
उदाहरण: Comparing Strings
print("apple" < "banana")
Operators को Chain करना
Python 0 <= score <= 100 जैसी chained comparisons की अनुमति देती है, जो स्वाभाविक पढ़ी जाती है और 0 <= score and score <= 100 लिखने के बराबर है — variable दोहराए बिना यह जाँचने का संक्षिप्त तरीका कि कोई value किसी सीमा में आता है।
उदाहरण: Chaining Operators
score = 75
print(0 <= score <= 100)
Chapter Quiz — Complete all 16 topics to unlock
0/16 topics done
Complete these topics first:
- Python print()
- Python input()
- Python Format Strings
- Python f-strings
- Python String Formatting
- Python Arithmetic Operators
- Python Relational Operators
- Python Logical Operators
- Python Bitwise Operators
- Python Assignment Operators
- Python Increment & Decrement
- Python Ternary Operator
- Python Operator Precedence
- Python Identity Operators
- Python Membership Operators
- Python Operators