← Back to Python Course | Chapter 2: Input, Output & Operators | Lesson 7 of 16

Python Relational Operators

Relational operators दो चीज़ों की तुलना करते हैं, जैसे यह पूछना कि क्या एक बच्चा दूसरे से लंबा है। जवाब हमेशा True या False होता है।
Syntax
python
result = a == b  # also !=, >, <, >=, <=

बराबरी और असमानता

== जाँचता है कि दो values बराबर हैं और != जाँचता है कि वे अलग हैं; दोनों हमेशा bool लौटाते हैं, और शुरुआती लोगों की आम गलती है वहाँ = (assignment) लिख देना जहाँ == (तुलना) चाहिए था।

उदाहरण: Equality and Inequality

python
print(5 == 5)
print(5 != 3)

बड़ा और छोटा

> और < दो values के परिमाण की तुलना करते हैं — संख्याएँ मान के आधार पर तुलनी जाती हैं, और नतीजा हमेशा True या False होता है, जो सीधे if statement की शर्त में इस्तेमाल के लिए तैयार है।

उदाहरण: Greater Than and Less Than

python
print(7 > 3)
print(2 < 1)

बड़ा-या-बराबर और छोटा-या-बराबर

>= और <= वैसे ही व्यवहार करते हैं जैसे > और <, पर बराबरी को भी शर्त पूरी करने वाला गिनते हैं, जो तब मायने रखता है जब कोई सीमा वाला value खुद वैध सीमा में शामिल होना चाहिए, जैसे "18 या उससे ज़्यादा" की आयु सीमा।

उदाहरण: Greater Than or Equal to and Less Than or Equal to

python
age = 18
print(age >= 18)

Strings की तुलना

Strings की तुलना lexicographically होती है, यानी हर character के अंतर्निहित code point के आधार पर character-दर-character — इसलिए "apple" < "banana" True है क्योंकि a b से पहले आता है, वही तर्क जो शब्दकोश वर्णानुक्रम के लिए इस्तेमाल करता है।

उदाहरण: Comparing Strings

python
print("apple" < "banana")

Operators को Chain करना

Python 0 <= score <= 100 जैसी chained comparisons की अनुमति देती है, जो स्वाभाविक पढ़ी जाती है और 0 <= score and score <= 100 लिखने के बराबर है — variable दोहराए बिना यह जाँचने का संक्षिप्त तरीका कि कोई value किसी सीमा में आता है।

उदाहरण: Chaining Operators

python
score = 75
print(0 <= score <= 100)
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.