Assignment Operators का उपयोग variables को values assign करने के लिए किया जाता है।
Operator
Example
Same As
=
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
Comparison operators
Comparison operators का उपयोग दो values को compare करने के लिए किया जाता है।
Operator
Name
Example
==
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
x = 20
y = 20
print("Equal : ", x==y)
print("Not equal : ",x!=y)
OUTPUT Equal : True
Not equal : False
a=15
b=26
print ("Greater than : ", a>b)
print("Less than : ", a<b)
print("Greater than or equal to : ",a >= b)
print("Less than or equal to : ",a <= b)
OUTPUT
Greater than : False
Less than : True
Greater than or equal to : False
Less than or equal to : True
Logical operators
Operator
Description
Example
and
यदि दोनों statements सही है तो यह true return करेगा।
x < 5 and x < 10
or
यदि दोनों statements में से एक statements भी सही है तो यह true return करेगा।
x < 5 or x < 4
not
यह result को reverse करता है अर्थात यदि result false है तो यह true return करेगा।
not(x < 5 and x < 10)
x = 20
print("AND Operator : ", x > 15 and x < 100)
OUTPUT AND Operator : True
x = 20
print("OR Operator : ", x < 15 or x < 100)
OUTPUT OR Operator : True
x = 20
print("Not Operator : ", not( x > 15 and x < 100))
OUTPUTNot Operator : False
Identity operators
Operator
Description
Example
is
यदि दोनों variable के पास एक सामान object हो तो यह true return करता है।
x is y
is not
यदि दोनों variable के पास एक सामान object नहीं हो तो यह true return करता है।
x is not y
x = ["Mango", "banana"]
y = ["Mango", "banana"]
z = x
print(x is z)
# return true आएगा क्योकि z और x में एक समान object हैं।
print(x is y)
# return False आएगा क्योकिx और y में एक समान object नहीं हैं। भले ही उनके पास समान content हो। OUTPUT
True
False
--------------------------------------------------------------------------------------
print(x is not z)
# return False आएगा क्योकि z और x में एक समान object हैं।
print(x is not y)
# return True आएगा क्योकि x और y में एक समान object नहीं हैं। भले ही उनके पास समान content हो।
OUTPUT
False
True
Membership operators
Operator
Description
Example
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
Bitwise operators
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