पायथन ऑपरेटर्स
पायथन ऑपरेटर्स
ऑपरेटरों का उपयोग चर और मूल्यों पर संचालन करने के लिए किया जाता है।
नीचे दिए गए उदाहरण में, हम +
दो मानों को एक साथ जोड़ने के लिए ऑपरेटर का उपयोग करते हैं:
उदाहरण
print(10 + 5)
पायथन ऑपरेटरों को निम्नलिखित समूहों में विभाजित करता है:
- अंकगणितीय आपरेटर
- असाइनमेंट ऑपरेटर
- तुलना ऑपरेटर
- लॉजिकल ऑपरेटर्स
- पहचान ऑपरेटर
- सदस्यता ऑपरेटर
- बिटवाइज़ ऑपरेटर
पायथन अंकगणित ऑपरेटर
अंकगणितीय ऑपरेटरों का उपयोग सामान्य गणितीय कार्यों को करने के लिए संख्यात्मक मानों के साथ किया जाता है:
Operator | Name | Example | Try it |
---|---|---|---|
+ | Addition | x + y | |
- | Subtraction | x - y | |
* | Multiplication | x * y | |
/ | Division | x / y | |
% | Modulus | x % y | |
** | Exponentiation | x ** y | |
// | Floor division | x // y |
पायथन असाइनमेंट ऑपरेटर्स
असाइनमेंट ऑपरेटरों का उपयोग वेरिएबल्स को मान निर्दिष्ट करने के लिए किया जाता है:
Operator | Example | Same As | Try it |
---|---|---|---|
= | x = 5 | x = 5 | |
+= | x += 3 | x = x + 3 | |
-= | x -= 3 | x = x - 3 | |
*= | x *= 3 | x = x * 3 | |
/= | x /= 3 | x = x / 3 | |
%= | x %= 3 | x = x % 3 | |
//= | x //= 3 | x = x // 3 | |
**= | x **= 3 | x = x ** 3 | |
&= | x &= 3 | x = x & 3 | |
|= | x |= 3 | x = x | 3 | |
^= | x ^= 3 | x = x ^ 3 | |
>>= | x >>= 3 | x = x >> 3 | |
<<= | x <<= 3 | x = x << 3 |
पायथन तुलना ऑपरेटर्स
तुलना ऑपरेटरों का उपयोग दो मानों की तुलना करने के लिए किया जाता है:
Operator | Name | Example | Try it |
---|---|---|---|
== | Equal | x == y | |
!= | Not equal | x != y | |
> | Greater than | x > y | |
< | Less than | x < y | |
>= | Greater than or equal to | x >= y | |
<= | Less than or equal to | x <= y |
पायथन लॉजिकल ऑपरेटर्स
सशर्त बयानों को संयोजित करने के लिए तार्किक ऑपरेटरों का उपयोग किया जाता है:
Operator | Description | Example | Try it |
---|---|---|---|
and | Returns True if both statements are true | x < 5 and x < 10 | |
or | Returns True if one of the statements is true | x < 5 or x < 4 | |
not | Reverse the result, returns False if the result is true | not(x < 5 and x < 10) |
पायथन आइडेंटिटी ऑपरेटर्स
पहचान संचालकों का उपयोग वस्तुओं की तुलना करने के लिए किया जाता है, यदि वे समान नहीं हैं, लेकिन यदि वे वास्तव में एक ही वस्तु हैं, तो समान स्मृति स्थान के साथ:
Operator | Description | Example | Try it |
---|---|---|---|
is | Returns True if both variables are the same object | x is y | |
is not | Returns True if both variables are not the same object | x is not y |
पायथन सदस्यता ऑपरेटर
सदस्यता ऑपरेटरों का उपयोग यह जांचने के लिए किया जाता है कि क्या किसी वस्तु में अनुक्रम प्रस्तुत किया गया है:
Operator | Description | Example | Try it |
---|---|---|---|
in | Returns True if a sequence with the specified value is present in the object | x in y | |
not in | Returns True if a sequence with the specified value is not present in the object | x not in y |
पायथन बिटवाइज ऑपरेटर्स
बिटवाइज़ ऑपरेटरों का उपयोग (बाइनरी) संख्याओं की तुलना करने के लिए किया जाता है:
Operator | Name | Description |
---|---|---|
& | AND | Sets each bit to 1 if both bits are 1 |
| | OR | Sets each bit to 1 if one of two bits is 1 |
^ | XOR | Sets each bit to 1 if only one of two bits is 1 |
~ | NOT | Inverts all the bits |
<< | Zero fill left shift | Shift left by pushing zeros in from the right and let the leftmost bits fall off |
>> | Signed right shift | Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off |