Greater than: True if left operand is greater than
right
<
Less than:
True if left operand is less than right
>=
Greater than or Equal to: True if left operand is
greater than or equal to right
<=
Less
than or Equal to: True if left operand is less than or equal to right
x = 57 + 60
y = 25 + 120
print(x)
print(y)
# x > y is False
print(x > y)
# x < y is True
print(x < y)
# x == y is False
print(x == y)
# x != y is True
print(x != y)
# x >= y is False
print(x >= y)
# x <= y is True
print(x <= y)
Output :
117
145
False
True
False
True
False
True
Bitwise Operator
Bitwise Operators
Description
&
Bitwise
AND
~
Bitwise NOT
|
Bitwise
OR
^
Bitwise XOR
<<
Bitwise
Left
>>
Bitwise Right
x = 15
y = 8
# bitwise AND operation
print(x & y)
# bitwise OR operation
print(x | y)
# Bitwise NOT operation
print(~ x)
# Bitwise XOR operation
print(x ^ y)
# Bitwise right shift operation
print(x >> 4)
# Bitwise left shift operation
print(x << 6)
Output :
8
15
-16
7
0
960
Logical Operators
Logical Operators
Description
AND
True
if both operands are true
OR
True if either of the
operands are true
NOT
True
of operand is False
x = 25
y = 30
# Print x and y if true
print(x < 100 and y < 100)
# Print a or y if true
print(x < 100 or y < 100)
# Print False if True statement
print (not(x < 100 and y < 100) )
Output :
True
True
False
Assignment operators
Assignment Operators
Description
=
Assign vale to right side
+=
Add right and left operand
-=
Subtract right and left
operand
%=
Takes modulus
/=
Divide left and right operand
*=
Multiply operands
a = 25
b = 6
b += a # += Operator
print(" += Operator Example: ", b)
b -= a # -= Operator
print("-= Operator Example:", b)
b *= a # *= Operator
print("*= Operator Example: ", b)
b //= a # //= Operator
print("//= Operator Example: ", b)
b **= a # **= Operator
print("**= Operator Example: ", b)
b /= a # /= Operator
print("/= Operator Example:", b)
b %= a # %= Operator
print("%= Operator Example: ", b)
x = 55
y = 92
x &= y # &= Operator
print("&= Operator Example: ", x)
x |= 9 # |= Operator
print("|= Operator Example: ", x)
x ^= y # Using ^= Operator
print("^= Operator Example: ", x)