Python के Operators
In this page:
result = operand1 operator operand2
result = operator operand
Arithmetic Operators: गणित करना
Arithmetic operators -- +, -, *, /, // (floor division), % (modulo), और ** (exponentiation) -- संख्याओं पर गणितीय गणनाएँ करते हैं, और (विशेष रूप से + ) strings और lists पर जोड़ के बजाय concatenation या दोहराव के अर्थ में भी काम करते हैं।
उदाहरण: Arithmetic Operators: Doing Math
print(7 + 3, 7 - 3, 7 * 3, 7 / 3, 7 // 3, 7 % 3, 7 ** 2)
Comparison Operators: संबंध जाँचना
Comparison operators -- ==, !=, <, >, <=, >= -- दो values की तुलना करते हैं और हमेशा boolean नतीजा (True या False) देते हैं, जो if statement या while loop में इस्तेमाल होने वाली हर शर्त के बुनियादी घटक हैं।
उदाहरण: Comparison Operators: Testing Relationships
print(5 == 5, 5 != 3, 5 > 3, 5 < 3)
Logical Operators: शर्तों को जोड़ना
Logical operators -- and, or, not -- कई boolean expressions को एक समग्र नतीजे में जोड़ते हैं। and के लिए दोनों पक्षों का True होना ज़रूरी है, or के लिए कम से कम एक पक्ष का True होना, और not सिर्फ़ एक boolean value को उलट देता है।
उदाहरण: Logical Operators: Combining Conditions
a, b = True, False
print(a and b, a or b, not a)
Assignment Operators: Values को Store और Update करना
value assign करने के बुनियादी = से आगे, Python compound assignment operators देती है -- +=, -=, *=, /= और अन्य -- जो किसी variable को उसी के वर्तमान value के आधार पर एक संक्षिप्त चरण में अपडेट करते हैं, जैसे counter बढ़ाने के लिए count += 1।
उदाहरण: Assignment Operators: Storing and Updating Values
total = 10
total += 5 # compound assignment: adds 5 and stores the result back in total
print(total)
विशेष परिवार: Identity, Membership और Bitwise
रोज़मर्रा के operator परिवारों से आगे, Python में तीन और विशेष परिवार हैं: identity operators (is, is not) जाँचते हैं कि दो variables ठीक एक ही object का संदर्भ देते हैं या नहीं; membership operators (in, not in) जाँचते हैं कि कोई value collection के भीतर मौजूद है या नहीं; और bitwise operators (&, |, ^, ~, <<, >>) integers के अलग-अलग bits को सीधे संचालित करते हैं।
उदाहरण: Specialized Families: Identity, Membership, and Bitwise
x = [1, 2]
y = x # y references the same list object as x
print(x is y) # identity operator: True, same object
print(1 in x) # membership operator: True, 1 is in the list
print(2 & 3) # bitwise operator: AND on the bits of 2 and 3
- = (assignment) को == (comparison) से confuse करना -- एक single = किसी variable की value set करता है, जबकि == check करता है कि दो values equal हैं या नहीं, और इन्हें मिला देना beginners की सबसे common गलतियों में से एक है।
- यह मान लेना कि हर operator family अलग-अलग data types में एक जैसे व्यवहार करती है -- + numbers के लिए addition का मतलब है लेकिन strings के लिए concatenation, और यह context-dependence समझना ज़रूरी है।
- operator precedence भूल जाना और यह मान लेना कि operators strictly left to right evaluate होते हैं -- उदाहरण के लिए, multiplication addition से पहले होता है, जब तक parentheses कुछ और न कहें।
- Python operators को families में group करता है: arithmetic (math), comparison (relationships), logical (conditions combine करना), assignment (values store करना), identity, membership, और bitwise।
- हर operator family एक अलग तरह की problem solve करती है -- arithmetic values compute करता है, comparison और logical operators conditions में इस्तेमाल होने वाले True/False results produce करते हैं।
- Operator precedence तय करता है कि एक single expression में operators किस क्रम में evaluate होते हैं, mathematics के order of operations जैसा।
यहाँ बताई गई सभी operator families core Python syntax का हिस्सा हैं, और हर Python 3 version में समान रूप से supported हैं।
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