Programming में केवल डेटा (Data) को Store करना ही पर्याप्त नहीं होता, बल्कि उस डेटा पर विभिन्न प्रकार की गणनाएँ (Calculations), तुलना (Comparison) और निर्णय (Decision Making) भी करने पड़ते हैं। इन सभी कार्यों को करने के लिए Operators का उपयोग किया जाता है।
Operator एक विशेष चिन्ह (Symbol) या Keyword होता है जो एक या अधिक Operands (मान/Variables) पर कोई विशेष कार्य (Operation) करता है और परिणाम (Result) देता है।
उदाहरण के लिए, यदि हमें दो संख्याओं का जोड़ करना हो, दो मानों की तुलना करनी हो या यह जाँचना हो कि कोई शर्त सही (True) है या नहीं, तो Operators का उपयोग किया जाता है।
Python में कई प्रकार के Operators उपलब्ध हैं, जिनका उपयोग अलग-अलग परिस्थितियों में किया जाता है।
Operator वह चिन्ह (Symbol) या Keyword है जो किसी Variable या Value पर कोई विशेष कार्य करता है।
उदाहरण—
a = 10
b = 20
print(a + b)
Output
30
यहाँ + एक Arithmetic Operator है।
जिस Value या Variable पर Operator कार्य करता है, उसे Operand कहते हैं।
उदाहरण—
x = 15
y = 5
print(x * y)
यहाँ—
- x पहला Operand है।
- y दूसरा Operand है।
- * Operator है।
Python में मुख्य रूप से निम्न प्रकार के Operators होते हैं—
- Arithmetic Operators
- Assignment Operators
- Comparison (Relational) Operators
- Logical Operators
- Bitwise Operators
- Identity Operators
- Membership Operators
Arithmetic Operators का उपयोग गणितीय (Mathematical) गणनाओं के लिए किया जाता है।
|
Operator |
कार्य |
उदाहरण |
|
+ |
जोड़ (Addition) |
a + b |
|
- |
घटाना (Subtraction) |
a - b |
|
* |
गुणा (Multiplication) |
a * b |
|
/ |
भाग (Division) |
a / b |
|
// |
पूर्णांक भाग (Floor Division) |
a // b |
|
% |
शेषफल (Modulus) |
a % b |
|
** |
घात (Exponent) |
a ** b |
a = 15
b = 5
print(a + b)
Output
20
print(20 - 8)
Output
12
print(12 * 5)
Output
60
print(20 / 4)
Output
5.0
/ हमेशा Float परिणाम देता है।
print(17 // 5)
Output
3
यह केवल पूर्णांक (Integer) भाग देता है।
print(17 % 5)
Output
2
यह भाग देने के बाद बचा हुआ शेषफल (Remainder) देता है।
print(2 ** 4)
Output
16
Arithmetic Operators का संयुक्त उदाहरण
a = 20
b = 6
print("Addition :", a + b)
print("Subtraction :", a - b)
print("Multiplication :", a * b)
print("Division :", a / b)
print("Floor Division :", a // b)
print("Modulus :", a % b)
print("Exponent :", a ** 2)
Assignment Operators का उपयोग Variables में Value Assign या Update करने के लिए किया जाता है।
|
Operator |
उदाहरण |
अर्थ |
|
= |
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 |
Floor Division Assign |
|
%= |
x %= 5 |
Modulus Assign |
|
**= |
x **= 2 |
Exponent Assign |
x = 10
x += 5
print(x)
Output
15
इनका उपयोग दो Values की तुलना (Comparison) करने के लिए किया जाता है।
|
Operator |
अर्थ |
|
== |
बराबर |
|
!= |
बराबर नहीं |
|
> |
बड़ा |
|
< |
छोटा |
|
>= |
बड़ा या बराबर |
|
<= |
छोटा या बराबर |
a = 15
b = 20
print(a == b)
print(a != b)
print(a > b)
print(a < b)
Output
False
True
False
True
Logical Operators का उपयोग एक से अधिक Conditions को जोड़ने के लिए किया जाता है।
|
Operator |
अर्थ |
|
and |
दोनों True हों |
|
or |
कोई एक True हो |
|
not |
Result उल्टा कर देता है |
age = 20
citizen = True
print(age >= 18 and citizen)
Output
True
print(True or False)
Output
True
print(not True)
Output
False
Bitwise Operators Binary Bits पर कार्य करते हैं।
|
Operator |
कार्य |
|
& |
AND |
|
| |
OR |
|
^ |
XOR |
|
~ |
NOT |
|
<< |
Left Shift |
|
>> |
Right Shift |
print(5 & 3)
Output
1
Bitwise Operators का उपयोग Low-Level Programming, Networking, Embedded Systems और Performance आधारित Applications में अधिक किया जाता है।
Identity Operators यह जाँचते हैं कि दो Variables एक ही Object को Refer कर रहे हैं या नहीं।
|
Operator |
अर्थ |
|
is |
समान Object |
|
is not |
समान Object नहीं |
a = [1, 2]
b = a
print(a is b)
Output
True
Membership Operators का उपयोग यह जाँचने के लिए किया जाता है कि कोई Value किसी Sequence (List, Tuple, String, Set, Dictionary आदि) में मौजूद है या नहीं।
|
Operator |
अर्थ |
|
in |
मौजूद है |
|
not in |
मौजूद नहीं है |
fruits = ["Apple", "Mango", "Banana"]
print("Mango" in fruits)
print("Orange" not in fruits)
Output
True
True
Operator Precedence (ऑपरेटर प्राथमिकता)
जब एक Expression में कई Operators होते हैं, तो Python एक निश्चित क्रम (Order of Precedence) के अनुसार उन्हें Execute करता है।
- () Parentheses
- ** Exponent
- *, /, //, %
- +, -
- Comparison Operators
- not
- and
- or
print(5 + 2 * 3)
Output
11
पहले 2 * 3 = 6 होगा, फिर 5 + 6 = 11।
print((5 + 2) * 3)
Output
21
|
Operator Type |
उपयोग |
|
Arithmetic |
गणितीय कार्य |
|
Assignment |
Value Assign करना |
|
Comparison |
तुलना करना |
|
Logical |
Conditions जोड़ना |
|
Bitwise |
Binary Bits पर कार्य |
|
Identity |
Object की पहचान |
|
Membership |
Collection में Value ढूँढना |
- जटिल Expressions में Parentheses () का उपयोग करें।
- == और = में अंतर समझें।
- Bitwise Operators का उपयोग तभी करें जब उनकी आवश्यकता हो।
- Membership और Identity Operators का उपयोग सही परिस्थिति में करें।
- Code को पढ़ने योग्य (Readable) बनाए रखें।
परीक्षा की दृष्टि से महत्वपूर्ण तथ्य
- +, -, *, / Arithmetic Operators हैं।
- = Assignment Operator है।
- == Comparison Operator है।
- and, or, not Logical Operators हैं।
- is और is not Identity Operators हैं।
- in और not in Membership Operators हैं।
- // Floor Division तथा % Modulus Operator है।
- () की Priority सबसे अधिक होती है।
Frequently Asked Questions (FAQs)
प्रश्न 1. Operator क्या होता है?
Operator एक Symbol या Keyword है जो Variables या Values पर कोई Operation करता है।
प्रश्न 2. Python में कितने प्रकार के Operators होते हैं?
मुख्य रूप से 7 प्रकार—Arithmetic, Assignment, Comparison, Logical, Bitwise, Identity और Membership।
प्रश्न 3. == और = में क्या अंतर है?
= का उपयोग Value Assign करने के लिए होता है, जबकि == दो Values की तुलना करने के लिए।
प्रश्न 4. // और / में क्या अंतर है?
/ सामान्य Division करता है और Float परिणाम देता है, जबकि // Floor Division करके पूर्णांक भाग देता है।
प्रश्न 5. in Operator का उपयोग कहाँ होता है?
किसी List, Tuple, String, Set या Dictionary में Value की उपस्थिति जाँचने के लिए।
- Operator = Operation करने वाला Symbol
- Operand = जिस Value पर Operation होता है
- Arithmetic = + - * / // % **
- Assignment = = += -= *= /=
- Comparison = == != > < >= <=
- Logical = and or not
- Bitwise = & | ^ ~ << >>
- Identity = is, is not
- Membership = in, not in
- () की Priority सबसे अधिक होती है।
Python Input(), Output(), print() Function और Type Casting — इसमें User Input लेना, print() Function, Formatting, Escape Characters, input() Function, Multiple Inputs, Type Casting (int(), float(), str(), bool()) तथा Practical Programs को विस्तार से सीखेंगे।