Python Operators क्या हैं? सभी Operators | Arithmetic, Comparison, Logical, Assignment & More | RBSE Class 12
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
= 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 हैं:
isis 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 हो सकते हैं।
== equality/value comparison के लिए होता है जबकि
is object identity check करने के लिए उपयोग होता है।
6. Membership Operators
Membership Operators का उपयोग यह check करने के लिए किया जाता है कि कोई value किसी sequence या collection में मौजूद है या नहीं।
दो membership operators हैं:
innot 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
() का उपयोग करें।
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
- Python Operator क्या है?
- Python के विभिन्न प्रकार के Operators लिखिए।
- Arithmetic Operators क्या हैं?
- Modulus Operator (%) का क्या उपयोग है?
- Exponentiation Operator क्या है?
- Floor Division Operator क्या है?
- Assignment Operator और Comparison Operator में अंतर लिखिए।
- Comparison Operators के नाम लिखिए।
- Logical Operators कौन-कौन से हैं?
- Identity Operators क्या हैं?
- Membership Operators क्या हैं?
- Bitwise Operators क्या हैं?
==और=में अंतर लिखिए।isऔर==में अंतर बताइए।- दो 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 पढ़ें
%, //, ==,
and, or, in और is
के examples का अभ्यास करें।
Python Operators और expressions की विस्तृत जानकारी के लिए Python की official documentation देखें।