OPERATOR DESCRIPTION SYNTAX FUNCTION IN-PLACE METHOD
> Greater than a > b gt(a, b) __gt__(self, other)
>= Greater or equal to a >= b ge(a, b) __ge__(self, other)
< Less than a < b lt(a, b) __lt__(self, other)
<= Less or equal to a <= b le(a, b) __le__(self, other)
== Equal to a == b eq(a, b) __eq__(self, other)
!= Not equal to a != b ne(a, b) __ne__(self, other)
OPERATOR DESCRIPTION SYNTAX FUNCTION IN-PLACE METHOD
+ Addition a + b add(a, b) __add__(self, other)
– Subtraction a - b sub(a, b) __sub__(self, other)
* Multiplication a * b mul(a, b) __mul__(self, other)
/ True Division a / b truediv(a, b) __truediv__(self, other)
// Floor Division a // b floordiv(a, b) __floordiv__(self, other)
% Modulo a % b mod(a, b) __mod__(self, other)
** Power a ** b pow(a, b) __pow__(self, other)
OPERATOR DESCRIPTION SYNTAX FUNCTION IN-PLACE METHOD
& Bitwise AND a & b and_(a, b) __and__(self, other)
| Bitwise OR a | b or_(a,b) __or__(self, other)
^ Bitwise XOR a ^ b xor(a, b) __xor__(self, other)
~ Bitwise NOT ~ a invert(a) __invert__(self)
>> Bitwise R shift a >> b rshift(a, b) __irshift__(self, other)
<< Bitwise L shift a << b lshift(a, b) __lshift__(self, other)
------------------------------------------
OPERATOR | SYNTAX |
----------------------
and | a and b |
----------------------
if condition1 and condition2 and condition3:
all_conditions_met == true
else:
all_conditions_met == false
------------------------------------------
OPERATOR | SYNTAX |
----------------------
or | a or b |
----------------------
if condition1 or condition2 or condition3:
any_condition_met == true
else:
any_condition_met == false
------------------------------------------
OPERATOR | SYNTAX |
----------------------
not | not a |
----------------------
if not equal_to_condition:
equal_to_condition == false
else:
equal_to_condition == true
print(10 + 30)
print(-10 + 20)
print(1 + 2.66)
print(1.2 + 1.2)
print(60 - 30)
print(-30 - 20)
print(-30 - -20)
print(5.66 - 3.44)
print(10 * 3)
print(5 + 10 * 100)
print((5 + 10) * 100)
print(100 / 20)
print(int(100 / 20))
print(8 % 2)
print(9 % 2)
print(20 % 5)
print(22 % 5)
print(2 ** 5)
print(2 * 2 * 2 * 2 * 2)
print(5 ** 4)
print(5 * 5 * 5 * 5)
print(100 // 20)
print(119 // 20)
print(120 // 20)
print(140 // 20)
print(142 // 20)
>>> s1 = {"a", "b", "c"}
>>> s2 = {"d", "e", "f"}
>>>
>>> s1 | s2
{'a', 'b', 'c', 'd', 'e', 'f'}
>>> s1
{'a', 'b', 'c'}
>>>
>>> s1 |= s2
>>> s1
{'a', 'b', 'c', 'd', 'e', 'f'}
a = 3
b = 4
print("The value of 3+4 is ", 3+4)
print("The value of 3-4 is ", 3-4)
print("The value of 3*4 is ", 3*4)
print("The value of 3/4 is ", 3/4)
a = 34
a -= 12
a *= 12
a /= 12
print(a)
b = (14!=7)
print(b)
bool1 = True
bool2 = False
print("The value of bool1 and bool2 is", (bool1 and bool2))
print("The value of bool1 or bool2 is", (bool1 or bool2))
print("The value of not bool2 is", (not bool2))
children_above_five= True
have_good_health= True
if children_above_five and have_good_health:
print("Eligible to get admission in Primary school.")
children_above_five= True
have_good_health= False
if children_above_five or have_good_health:
print("Eligible to get admission in Primary school.")
children_above_five= True
have_good_health= False
if children_above_five and not have_good_health:
print("Eligible to get admission in Primary school.")