Python में Operators वे symbols होते हैं जो किसी operation को perform करने के लिए इस्तेमाल किए जाते हैं। Operator का उपयोग operands पर अलग-अलग कार्य (operations) करने के लिए किया जाता है। उदाहरण के लिए:- जोड़, गुणा, भाग आदि।
Types of Python Operators in Hindi
Python में मुख्य रूप से सात प्रकार के operators होते हैं:
- Arithmetic Operators
- Comparison Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Identity Operators
- Membership Operators
चलिये, इन operators को विस्तार में समझते हैं।
1. Arithmetic Operators
Arithmetic operators का उपयोग गणितीय (Mathematical) कार्यों के लिए किया जाता है, जैसे- addition (जोड़), subtraction (घटाना), multiplication (गुणा), division (भाग) आदि। नीचे कुछ प्रमुख arithmetic operators हैं:
Operator | Description | Example |
+ | Addition (जोड़) | a + b |
– | Subtraction (घटाव) | a – b |
* | Multiplication (गुणा) | a * b |
/ | Division (भाग) | a / b |
% | Modulus (शेष) | a % b |
** | Exponentiation (घातांक) | a ** b |
// | Floor Division (पूर्ण भाग) | a // b |
2. Comparison Operators
Comparison operators का उपयोग दो values को compare करने के लिए किया जाता है। यह true या false को return करता है।
Operator | Description | Example |
== | Equal to (बराबर) | a == b |
!= | Not equal to (असमान) | a != b |
> | Greater than (बड़ा) | a > b |
< | Less than (छोटा) | a < b |
>= | Greater than or equal to (बड़ा या बराबर) | a >= b |
<= | Less than or equal to (छोटा या बराबर) | a <= b |
3. Logical Operators
Logical operators का उपयोग logical statements को जोड़ने के लिए किया जाता है। ये boolean values (True, False) को return करते हैं।
Operator | Description | Example |
and | यदि दोनों स्टेटमेंट true हों तो ही true | a and b |
or | यदि कोई भी एक स्टेटमेंट true हो तो true | a or b |
not | यह statement को reverse (उल्टा) करता है। | not a |
4. Bitwise Operators
Bitwise operators का उपयोग binary numbers पर operations करने के लिए किया जाता है।
Operator | Description | Example |
& | AND | a & b |
| | OR | a | b |
^ | XOR | a ^ b |
~ | NOT | ~a |
<< | Left Shift | a << 1 |
>> | Right Shift | a >> 1 |
5. Assignment Operators
Assignment operators का उपयोग variables को values प्रदान (assign) करने के लिए किया जाता है।
operators | description | उदाहरण | same as |
= | यह बायीं तरफ के expression को वैल्यू assign करता है. | x = 5 | x = 5 |
+= | यह right operand को left operand से जोड़ता है तथा जो result आता है उसे left operand को assign करता है. | x += 5 | x = x + 5 |
-= | यह right operand को left operand में घटाता है तथा जो result आता है उसे left operand को assign करता है. | x -= 5 | x = x – 5 |
*= | यह right operand को left operand में गुणा करता है तथा जो result आता है उसे left operand को assign करता है. | x *= 5 | x = x * 5 |
/= | यह left operand को right operand से divide करता है तथा जो result आता है उसे left operand को assign करता है. | x /= 5 | x = x / 5 |
%= | यह दो operands का modulus लेता है और उसे left operand को assign करता है. | x %= 5 | x = x % 5 |
**= | यह operands में power (घात) को परफॉर्म करता है तथा उसे left operand को assign करता है. | x **= 5 | x = x ** 5 |
//= | यह operators में floor division को परफॉर्म करता है तथा उसे left operand को assign करता है. | x //= 5 | x = x // 5 |
6. Identity Operators
Identity operators का उपयोग यह check करने के लिए किया जाता है कि दो variables एक ही memory location को refer करते हैं या नहीं।
Operator | Description | Example |
is | यदि दोनों variables समान हों | a is b |
is not | यदि दोनों variables अलग हों | a is not b |
7. Membership Operators
Membership operators का उपयोग यह check करने के लिए किया जाता है कि कोई value किसी sequence (जैसे list, tuple, string) का हिस्सा है या नहीं।
Operator | Description | Example |
in | यदि value sequence में है | a in b |
not in | यदि value sequence में नहीं है | a not in b |
इसे भी पढ़ें:-
निवेदन:- अगर आपको यह पोस्ट उपयोगी लगी हो तो इसे अपने दोस्तों के साथ अवश्य share कीजिए ताकि वो भी इसका लाभ ले सकें। धन्यवाद।
What will be the result of the expression ‘x’ and’a’? Plz explain this.