Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🐍 Unit 2 – Python Basics  ·  Lesson 13

Operators, Expressions और Precedence

Operators और operands

Operator एक symbol है जो कोई operation करता है; जिन values पर वह काम करता है वे operands हैं। marks + 5 में + operator है और marks और 5 operands। एक operand वाला operator (जैसे -x या not x) unary है; दो वाला binary।

➕
Arithmetic+ - * / // % **
⚖️
Relational== != > < >= <=
📝
Assignment= += -= *= /= //= %= **=
🔀
Logicaland, or, not
🆔
Identityis, is not
📦
Membershipin, not in
Python operators के परिवार

Arithmetic operators

Operatorमतलब17 ? 5
+जोड़22
-घटाव12
*गुणा85
/भाग (हमेशा float)3.4
//Floor division (भागफल)3
%Modulus (शेषफल)2
**Exponent (घात)17**2 = 289
Python
a, b = 17, 5
print(a + b, a - b, a * b)
print(a / b, a // b, a % b, a ** 2)
print(-17 // 5, -17 % 5)        # floor division rounds DOWN
22 12 85 3.4 3 2 289 -4 3
💡 % और // के uses

n % 2 == 0 even number जाँचता है; n % 10 आख़िरी digit देता है; n // 10 आख़िरी digit हटाता है। + strings जोड़ता भी है ('Py' + 'thon') और * उन्हें दोहराता है ('-' * 20)।

Relational (comparison) operators

ये दो values compare करते हैं और हमेशा True या False देते हैं।

Python
a, b = 17, 5
print(a > b, a < b, a == 17, a != b, a >= 17, b <= 4)
print('apple' < 'banana', 'Zoo' < 'apple')   # compared by Unicode codes
True False True True True False True True

Strings अक्षर-दर-अक्षर Unicode codes से compare होती हैं; capital letters (65–90) small letters (97–122) से पहले आते हैं, इसलिए 'Zoo' < 'apple' True है।

Assignment operators

x += 5 जैसा compound assignment x = x + 5 का छोटा रूप है।

Python
x = 10
x += 5;  print(x)
x -= 3;  print(x)
x *= 2;  print(x)
x //= 5; print(x)
x **= 3; print(x)
x %= 10; print(x)
15 12 24 4 64 4

Logical operators

ABA and BA or Bnot A
TrueTrueTrueTrueFalse
TrueFalseFalseTrueFalse
FalseTrueFalseTrueTrue
FalseFalseFalseFalseTrue
and, or, not की truth table
Python
age, has_id = 20, False
print(age >= 18 and has_id)    # both must be True
print(age >= 18 or has_id)     # any one True is enough
print(not has_id)
print(0 and 5, 3 and 5, 0 or 'default', '' or 'guest')
False True True 0 5 default guest

Short-circuit: and पहली false value पर रुक जाता है; or पहली true value पर, और वे वही value return करते हैं। इसीलिए '' or 'guest' से 'guest' मिलता है — default values के लिए काम का।

Identity और membership operators

Python
L = [1, 2, 3]
M = L
N = [1, 2, 3]
print(M is L, N is L)        # identity: same object?
print(N == L, N is not L)    # equality: same value?
print('a' in 'class', 5 in [1, 2, 3], 'z' not in 'python')
True False True True True False True

== (equality)

  • क्या values same हैं?
  • N == L → True
  • Data compare करने के लिए

is (identity)

  • क्या same object है?
  • N is L → False (दो अलग lists)
  • मुख्यतः x is None के लिए
== और is को मिलाएँ नहीं

Bitwise operators

ये integers के binary digits पर काम करते हैं: & AND, | OR, ^ XOR, ~ NOT, << left shift, >> right shift।

Python
print(12 & 10, 12 | 10, 12 ^ 10)   # 1100 and 1010
8 14 6

12 = 1100 और 10 = 1010 → AND 1000 = 8, OR 1110 = 14, XOR 0110 = 6।

Expressions और precedence

Expression values, variables और operators का मेल है जिसे Python एक value में evaluate करता है, जैसे (a + b) / 2। Expression में कई operators हों तो precedence तय करती है कि पहले क्या होगा, और associativity बराबर precedence वाले operators का क्रम (ज़्यादातर बाएँ से दाएँ; ** दाएँ से बाएँ)।

( )parentheses – सबसे ऊपर**exponent (दाएँ से बाएँ)+x -x ~xunary* / // %multiplicative+ -additive== != > < >= <= is incomparisonsnotandorसबसे नीचे
Operator precedence (ऊपर वाला पहले)
Python
print(2 + 3 * 4)        # * before +
print((2 + 3) * 4)      # brackets first
print(2 ** 3 ** 2)      # ** is right to left: 2 ** 9
print(10 - 4 - 3)       # left to right
print(100 / 10 * 2)     # left to right
print(5 + 4 > 8 and not 3 > 4)
14 20 512 3 20.0 True
🧮 Solved: 12 + 3 * 2 ** 2 // 4 - 1

2 ** 2 = 4 → 3 * 4 = 12 → 12 // 4 = 3 → 12 + 3 = 15 → 15 − 1 = 14।

सारांश और practice

  • / float देता है, // floor quotient, % remainder, ** power।
  • Comparisons True/False देते हैं; logical operators short-circuit करते हैं।
  • is identity, == value, in membership जाँचता है।
  • Precedence: () → ** → unary → * / // % → + - → comparisons → not → and → or।
✅ Practice

Output बताइए: (a) print(15 % 4 + 2 ** 3) (b) print(-9 // 2) (c) print(not 5 > 3 or 2 == 2) (d) print(10 / 4 * 2)

Answers: (a) 11 (b) -5 (c) True (d) 5.0

अक्सर पूछे जाने वाले प्रश्न (FAQ)

Python में / और // में क्या फ़र्क है?
/ true division है और हमेशा float देता है (7/2 = 3.5)। // floor division है और result से बड़ा न होने वाला सबसे बड़ा पूर्ण number देता है (7//2 = 3, -7//2 = -4)।
== और is में क्या फ़र्क है?
== जाँचता है कि दो values बराबर हैं या नहीं। is जाँचता है कि दो names memory में बिल्कुल एक ही object को refer करते हैं या नहीं।
किस operator की precedence सबसे ज़्यादा है?
पहले brackets (), फिर exponent **, फिर unary + और -, फिर * / // %, फिर + -, फिर comparisons, फिर not, and, or।
← Class 11 Computer Science
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicInput, Output, Type Conversion और Errors आपकी प्रगति: 13 / 29 (45%) · Lesson 14 / 29 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें