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
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