Types of operators:
➢ Arithmetic operators.
➢ Comparison operators.
➢ Logical operators.
➢ Bitwise operators.
➢ Assignment operators.
➢ Membership operators.
➢ Identity operators.
Arithmetic operators:
Assignment = a=b Give b value of a
Addition + a+b Add a value to b value
Subtraction - a -b Subtract a value from b value
Unary plus + +a Multiply a value by the factor +
Unary minus - -a Multiply a value by the factor -
Multiplication * a*b Multiply a value by b value
Exponent ** a ** b a power b
Division / a/b Divide a value by b value
Floor divide // a // b Divide value a by value b and
return the nearest integer.
Modulo % a%b To get the last digit that
remains when we divide
value a by value b
Arithmetic operators return always arithmetic values.
Comparison operators:
Equal to == a == b Is a value equal b value?
Not equal to != a != b Is a value not equal b value?
Greater than > a>b Is a value greater than b value?
Less than < a<b Is a value less than b value?
Greater than or equal to >= a >= b Is a value greater than or equal to b value?
Less than or equal to <= a <= b Is a value less than or equal to b value?
Comparison operators return True or False.
Logical operators:
Logical AND and a and b Are a value and b value equal True?
Logical OR or a or b Is the value of a or b or both equal True?
Logical NOT not not a Is the value a not worth it True?
Logical operators return True or False.
Bitwise operators:
Bitwise AND & a&b calculates the sum of the bits shared between a
and b.
Bitwise OR | a|b calculates the sum of the shared and unshared
bits between a and b.
Bitwise XOR ^ a^b calculates the sum of the bits not shared
between a and b.
Assignment operators:
Basic Assignment = a=b a=b
Add Assignment += a += b a=a+b
Subtract Assignment -= a -= b a=a-b
Multiply Assignment *= a *= b a=a*b
Exponent Assignment **= a **= b a = a ** b
Divide Assignment /= a /= b a=a/b
Floor Divide Assignment //= a //= b a = a // b
Modulo assignment %= a %= b a=a%b
Bitwise AND Assignment &= a &= b a=a%b
Bitwise OR Assignment |= a |= b a=a|b
Bitwise exclusive OR Assignment ^= a ^= b a=a^b
Membership operators:
IN in a in arr Is the value of the variable a present in the array arr?
NOT IN not in a not in arr Is the variable value a not present in the array arr?
Identity operators:
IS is a is b Do object a and object b refer to the same object in
memory?
IS NOT is not a is not b Do object a and object b not refer to the same object
in memory?
NOT IN in membership operators => not before in
IS NOT in identity operators => not after is