Python Operators क्या हैं? सभी Operators | Arithmetic, Comparison, Logical, Assignment & More | RBSE Class 12

इस लेख में: Python Operators क्या हैं, Arithmetic, Assignment, Comparison, Logical, Identity, Membership और Bitwise Operators को examples और practical programs के साथ आसान हिंदी में समझेंगे।

Python Operator क्या है?

Operator एक special symbol या keyword होता है जिसका उपयोग values और variables पर कोई operation करने के लिए किया जाता है।

उदाहरण:

a = 10
b = 5

print(a + b)

यहाँ + एक Arithmetic Operator है, जो दो numbers को जोड़ता है।

Python Operators के प्रमुख प्रकार

Operator Type मुख्य Operators
Arithmetic Operators +, -, *, /, %, **, //
Assignment Operators =, +=, -=, *=, /=, %= आदि
Comparison Operators ==, !=, >, <, >=, <=
Logical Operators and, or, not
Identity Operators is, is not
Membership Operators in, not in
Bitwise Operators &, |, ^, ~, <<, >>

1. Arithmetic Operators

Arithmetic Operators का उपयोग mathematical calculations करने के लिए किया जाता है।

Operator नाम Example
+ Addition 10 + 5
- Subtraction 10 - 5
* Multiplication 10 * 5
/ Division 10 / 5
% Modulus 10 % 3
** Exponentiation 2 ** 3
// Floor Division 10 // 3

Addition (+)

a = 10
b = 5

print(a + b)

Output:

15

Subtraction (-)

a = 10
b = 5

print(a - b)

Output:

5

Multiplication (*)

a = 10
b = 5

print(a * b)

Output:

50

Division (/)

print(10 / 3)

/ operator division का result देता है और इसका result floating-point value हो सकता है।

Modulus (%)

Modulus operator division के बाद remainder देता है।

print(10 % 3)

Output:

1

Exponentiation (**)

Exponentiation operator power calculation के लिए उपयोग किया जाता है।

print(2 ** 3)

Output:

8

Floor Division (//)

Floor division quotient का floor result देता है।

print(10 // 3)

Output:

3

2. Assignment Operators

Assignment Operators variables को values assign या update करने के लिए उपयोग किए जाते हैं।

Operator Example अर्थ
= x = 10 Value assign करना
+= x += 5 x = x + 5
-= x -= 5 x = x - 5
*= x *= 5 x = x * 5
/= x /= 5 x = x / 5
%= x %= 5 x = x % 5
**= x **= 2 x = x ** 2
//= x //= 2 x = x // 2

Assignment Example

x = 10

x += 5

print(x)

Output:

15

3. Comparison Operators

Comparison Operators दो values की तुलना करते हैं और सामान्यतः True या False result देते हैं।

Operator अर्थ
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

Example

a = 10
b = 5

print(a > b)
print(a == b)
print(a != b)

Output:

True
False
True
Important: = assignment के लिए और == comparison के लिए उपयोग होता है।

4. Logical Operators

Logical Operators का उपयोग multiple conditions को combine करने के लिए किया जाता है।

Operator अर्थ
and दोनों conditions True होनी चाहिए
or कम से कम एक condition True हो
not Boolean result को उलटता है

and Operator

age = 20

print(age >= 18 and age <= 60)

Output:

True

or Operator

age = 15

print(age < 18 or age > 60)

Output:

True

not Operator

is_student = True

print(not is_student)

Output:

False

5. Identity Operators

Identity Operators यह check करते हैं कि दो references एक ही object को refer कर रहे हैं या नहीं।

Python में दो identity operators हैं:

  • is
  • is not

is Operator

a = [1, 2]
b = a

print(a is b)

यहाँ b उसी object को refer करता है जिसे a refer कर रहा है, इसलिए result True होगा।

is not Operator

a = [1, 2]
b = [1, 2]

print(a is not b)

दोनों lists में समान contents हो सकते हैं, लेकिन वे अलग objects हो सकते हैं।

Exam Tip: == equality/value comparison के लिए होता है जबकि is object identity check करने के लिए उपयोग होता है।

6. Membership Operators

Membership Operators का उपयोग यह check करने के लिए किया जाता है कि कोई value किसी sequence या collection में मौजूद है या नहीं।

दो membership operators हैं:

  • in
  • not in

in Operator

fruits = ["apple", "banana", "mango"]

print("apple" in fruits)

Output:

True

not in Operator

fruits = ["apple", "banana", "mango"]

print("orange" not in fruits)

Output:

True

7. Bitwise Operators

Bitwise Operators integers के binary representation के bits पर operations करने के लिए उपयोग किए जाते हैं।

Operator नाम
& AND
| OR
^ XOR
~ NOT
<< Left Shift
>> Right Shift

Bitwise AND Example

a = 5
b = 3

print(a & b)

Bitwise operators को समझने के लिए binary representation का ज्ञान महत्वपूर्ण है।

Operator Precedence क्या है?

जब एक expression में एक से अधिक operators होते हैं तो Python एक विशिष्ट precedence order के अनुसार operations perform करता है।

उदाहरण:

result = 10 + 5 * 2

print(result)

यहाँ multiplication पहले होगा और उसके बाद addition।

Output:

20
Tip: Expression को स्पष्ट बनाने के लिए जरूरत पड़ने पर parentheses () का उपयोग करें।

Parentheses के साथ Example

result = (10 + 5) * 2

print(result)

Output:

30

Arithmetic Operators का Practical Program

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))

print("Addition =", a + b)
print("Subtraction =", a - b)
print("Multiplication =", a * b)
print("Division =", a / b)

Comparison और Logical Operators का Practical Example

age = int(input("Enter your age: "))

print("Adult:", age >= 18)
print("Senior:", age >= 60)

Operators का Quick Revision

Type Operators मुख्य उपयोग
Arithmetic +, -, *, /, %, **, // Mathematical operations
Assignment =, +=, -=, *= Assignment/update
Comparison ==, !=, >, <, >=, <= Comparison
Logical and, or, not Conditions combine करना
Identity is, is not Object identity
Membership in, not in Collection में membership check
Bitwise &, |, ^, ~, <<, >> Bits पर operations

RBSE Class 12 Important Questions

  1. Python Operator क्या है?
  2. Python के विभिन्न प्रकार के Operators लिखिए।
  3. Arithmetic Operators क्या हैं?
  4. Modulus Operator (%) का क्या उपयोग है?
  5. Exponentiation Operator क्या है?
  6. Floor Division Operator क्या है?
  7. Assignment Operator और Comparison Operator में अंतर लिखिए।
  8. Comparison Operators के नाम लिखिए।
  9. Logical Operators कौन-कौन से हैं?
  10. Identity Operators क्या हैं?
  11. Membership Operators क्या हैं?
  12. Bitwise Operators क्या हैं?
  13. == और = में अंतर लिखिए।
  14. is और == में अंतर बताइए।
  15. दो numbers पर Arithmetic Operations करने का Python program लिखिए।

Frequently Asked Questions (FAQs)

Python Operator क्या है?

Operator एक symbol या keyword है जिसका उपयोग values या variables पर operation करने के लिए किया जाता है।

Python में Arithmetic Operators कौन-कौन से हैं?

मुख्य Arithmetic Operators हैं: +, -, *, /, %, ** और //

Python में Logical Operators कौन-कौन से हैं?

Python में मुख्य Logical Operators and, or और not हैं।

Python में == और = में क्या अंतर है?

= assignment के लिए जबकि == equality comparison के लिए उपयोग किया जाता है।

Python में Membership Operators कौन-कौन से हैं?

in और not in Python के Membership Operators हैं।

अब अगला Topic पढ़ें

RBSE Python Study Tip: Operators को अच्छी तरह समझने के लिए केवल definitions याद न करें। हर operator का छोटा program खुद लिखें और उसका output check करें। विशेष रूप से %, //, ==, and, or, in और is के examples का अभ्यास करें।
Official Reference:

Python Operators और expressions की विस्तृत जानकारी के लिए Python की official documentation देखें।

Python Expressions Documentation