Relational Operators in Python in hindi - Relational Operators in Python क्या हैं?

Arpit Nageshwar
⏰ 4 min read

Relational Operators in Python क्या हैं?

Table of Contents

Introduction to Relational Operators in Hindi

  • Python में जब भी हमें दो values के बीच तुलना (comparison) करनी होती है — जैसे यह check करना कि कौन सी value बड़ी है, छोटी है, या दोनों बराबर हैं — तो इसके लिए Relational Operators का इस्तेमाल किया जाता है।

  • इन्हें Comparison Operators भी कहा जाता है, क्योंकि इनका मुख्य काम ही दो operands के बीच relationship (जैसे greater, smaller, equal) को check करना होता है।

  • Relational Operators हमेशा एक Boolean value return करते हैं, यानी result या तो True होगा या False, कभी कोई तीसरा value नहीं आता।

  • यह operators programming में decision-making की नींव होते हैं, क्योंकि अधिकतर if, while जैसे conditional statements इन्हीं operators के result पर depend करते हैं।

  • Python में Relational Operators को numbers, strings, aur यहाँ तक कि कुछ अन्य data types के बीच भी इस्तेमाल किया जा सकता है, बशर्ते वे comparable हों।

  • इन्हें Arithmetic Operators से अलग समझना ज़रूरी है — Arithmetic Operators (जैसे +, -) कोई नई value calculate करते हैं, जबकि Relational Operators सिर्फ यह बताते हैं कि दो values के बीच कैसा संबंध (relation) है।

  • Exam की दृष्टि से इसकी सरल परिभाषा याद रखनी हो तो: "Relational operators are used to compare two values or expressions, and they always evaluate to a Boolean result — either True or False."

Types of Relational Operators in Hindi (==, !=, >, <, >=, <=)

Relational Operators ke Types Relational Operators == (Equal To) Do values barabar hain ya nahi != (Not Equal To) Do values barabar nahi hain > (Greater Than) Left value bada hai ya nahi < (Less Than) Left value chhota hai ya nahi >= (Greater or Equal) Bada ya barabar hai <= (Less or Equal) Chhota ya barabar hai
  • 1. Equal To (==):
    यह check करता है कि दोनों values आपस में बराबर हैं या नहीं। अगर बराबर हों तो True, वरना False return करता है।

    5 == 5 # True
    5 == 8 # False

  • 2. Not Equal To (!=):
    यह check करता है कि दोनों values आपस में अलग हैं या नहीं। अगर values अलग हों तो True, बराबर हों तो False return करता है।

    5 != 8 # True
    5 != 5 # False

  • 3. Greater Than (>):
    यह check करता है कि left side की value right side की value से बड़ी है या नहीं।

    10 > 5 # True
    3 > 5 # False

  • 4. Less Than (<):
    यह check करता है कि left side की value right side की value से छोटी है या नहीं।

    3 < 5 # True
    10 < 5 # False

  • 5. Greater Than or Equal To (>=):
    यह check करता है कि left side की value right side की value से बड़ी है या उसके बराबर है।

    5 >= 5 # True
    4 >= 5 # False

  • 6. Less Than or Equal To (<=):
    यह check करता है कि left side की value right side की value से छोटी है या उसके बराबर है।

    5 <= 5 # True
    6 <= 5 # False

Evaluating Relational Expressions in Hindi

  • जब भी Python में कोई relational expression लिखा जाता है, जैसे a > b, तो सबसे पहले दोनों operands (a और b) की values निकाली जाती हैं, फिर उनके बीच specified relation check होकर एक Boolean result मिलता है।

  • अगर expression में arithmetic operations भी शामिल हों, जैसे (a + b) > c, तो Python पहले bracket वाले arithmetic operation को evaluate करता है, और उसके बाद ही relational comparison perform करता है — यानी operator precedence का ध्यान रखा जाता है।

  • Python में relational operators को chain (जोड़) करके भी लिखा जा सकता है, जैसे 10 < x < 20, जिसका मतलब है कि यह check होगा कि x की value 10 से बड़ी और 20 से छोटी दोनों है — यह mathematics वाले "between" concept जैसा ही काम करता है।

  • Relational Operators सिर्फ numbers तक सीमित नहीं हैं — Strings को भी alphabetically compare किया जा सकता है, जैसे "apple" < "banana" का result True आएगा क्योंकि 'a' alphabetically 'b' से पहले आता है।

  • Different data types (जैसे string aur integer) को सीधे compare करने की कोशिश करने पर Python TypeError देता है, इसलिए comparison से पहले दोनों values के data type का compatible होना ज़रूरी है।

  • एक बार जब relational expression evaluate होकर True या False देता है, तो इस result को सीधे किसी variable में store किया जा सकता है, या फिर if, while जैसे control statements में condition के रूप में इस्तेमाल किया जा सकता है।

Applications of Relational Operators in Hindi

  • 1. Conditional Statements में:
    if, elif, else जैसे statements में relational operators का उपयोग यह decide करने के लिए होता है कि कौन सा block execute होगा, जैसे किसी student का pass/fail check करना।

  • 2. Loops को Control करने में:
    while loop में relational expression यह तय करता है कि loop कब तक चलता रहेगा — जैसे तब तक repeat करना जब तक कोई counter एक तय limit से कम है।

  • 3. Data Validation में:
    User से input लेते समय यह check करने के लिए इस्तेमाल होता है कि दी गई value valid range में है या नहीं — जैसे age 0 से 120 के बीच है या नहीं।

  • 4. Sorting और Searching Algorithms में:
    Sorting (जैसे Bubble Sort) और Searching (जैसे Binary Search) जैसे algorithms में elements को आपस में compare करने के लिए relational operators का लगातार उपयोग होता है।

  • 5. Filtering Data में:
    किसी list या dataset में से specific condition को पूरा करने वाले elements को filter out करने के लिए भी relational operators इस्तेमाल किए जाते हैं, जैसे 18 से ज़्यादा उम्र वाले लोगों को अलग निकालना।

Truth Table of Relational Operators in Python in Hindi

Truth Table (a = 10, b = 20 मानते हुए) Operator Expression Meaning Result == a == b 10 barabar 20 hai? False != a != b 10, 20 se alag hai? True > a > b 10, 20 se bada hai? False < a < b 10, 20 se chhota hai? True >= a >= b 10, 20 se bada ya barabar hai? False <= a <= b 10, 20 se chhota ya barabar hai? True Note: values badalne par result bhi according badal jaayega
Operator Expression (a=10, b=20) Result
==a == bFalse
!=a != bTrue
>a > bFalse
<a < bTrue
>=a >= bFalse
<=a <= bTrue

Frequently Asked Questions (FAQ) – Relational Operators in Python

वे operators जो दो values के बीच तुलना करके True या False return करते हैं, उन्हें Relational Operators (या Comparison Operators) कहते हैं, जैसे ==, !=, >, <

= Assignment Operator है जो value को variable में store करता है, जबकि == Relational Operator है जो दो values को compare करके Boolean result देता है।

हाँ, Python strings को alphabetically compare करता है, जैसे "apple" < "banana" का result True आता है।

यह एक साथ दो relational conditions को check करने का तरीका है, जिसमें यह देखा जाता है कि x दोनों conditions को एक साथ satisfy करता है या नहीं।

Relational Operators हमेशा एक Boolean value return करते हैं, यानी result सिर्फ True या False ही हो सकता है।

Arpit Nageshwar

✍️ Arpit Nageshwar

Post-graduated | Web Developer | +3 yr Experience | IIT Kharagpur Certified