1#PYTHON RELATIONAL OPERATORS
2OPERATOR DESCRIPTION SYNTAX FUNCTION IN-PLACE METHOD
3> Greater than a > b gt(a, b) __gt__(self, other)
4>= Greater or equal to a >= b ge(a, b) __ge__(self, other)
5< Less than a < b lt(a, b) __lt__(self, other)
6<= Less or equal to a <= b le(a, b) __le__(self, other)
7== Equal to a == b eq(a, b) __eq__(self, other)
8!= Not equal to a != b ne(a, b) __ne__(self, other)
9
10#PYTHON MATHEMATICAL OPERATORS
11OPERATOR DESCRIPTION SYNTAX FUNCTION IN-PLACE METHOD
12+ Addition a + b add(a, b) __add__(self, other)
13– Subtraction a - b sub(a, b) __sub__(self, other)
14* Multiplication a * b mul(a, b) __mul__(self, other)
15/ True Division a / b truediv(a, b) __truediv__(self, other)
16// Floor Division a // b floordiv(a, b) __floordiv__(self, other)
17% Modulo a % b mod(a, b) __mod__(self, other)
18** Power a ** b pow(a, b) __pow__(self, other)
19
20#PYTHON BITWISE OPERATORS
21OPERATOR DESCRIPTION SYNTAX FUNCTION IN-PLACE METHOD
22& Bitwise AND a & b and_(a, b) __and__(self, other)
23| Bitwise OR a | b or_(a,b) __or__(self, other)
24^ Bitwise XOR a ^ b xor(a, b) __xor__(self, other)
25~ Bitwise NOT ~ a invert(a) __invert__(self)
26>> Bitwise R shift a >> b rshift(a, b) __irshift__(self, other)
27<< Bitwise L shift a << b lshift(a, b) __lshift__(self, other)
1>>> s1 = {"a", "b", "c"}
2>>> s2 = {"d", "e", "f"}
3
4>>> # OR, |
5>>> s1 | s2
6{'a', 'b', 'c', 'd', 'e', 'f'}
7>>> s1 # `s1` is unchanged
8{'a', 'b', 'c'}
9
10>>> # In-place OR, |=
11>>> s1 |= s2
12>>> s1 # `s1` is reassigned
13{'a', 'b', 'c', 'd', 'e', 'f'}
14
1#The (!) is the not operator in Python, (!=) means not equal to.
2if 2!=10:
3 print("2 isn't equal to 10.")
4elif 2=10:
5 print("2 is equal to 10.")
6#Prints "2 isn't equal to 10." as 2 isn't equal to 10. Is it?