Python is a very rich language which makes it a bit hard to memorize everything, including operators.

If you want to learn more about operators then keep reading 🙂

Mathematical Operators (Arithmetic)


NameSyntax in PythonExample
Addition+2+1
Substraction2-1
Multiplication*2*1
Division/2/1
Modulus%2%1
Exponentiation**2**2
Floor Division//2//1

Comparison Operators


NameSyntax in PythonExample
Equal==a == b
Not Equal!=a != b
Less than<a < b
Greater than>a > b
Less than or equal<=a <= b
Greater than or equal>=a >= b

Assignment Operators


OperatorSimilar toUsage
=a = 6a = 6
+=a = a + 6a += 6
-=a = a – 6a -= 6
*=a = a * 6a *= 6
/=a = a / 6a /= 6
%=a = a % 6a %= 6
//=a = a // 6a //=6
**=a = a**6a **= 6

Logical Operators


Name & SyntaxDescriptionExample
andChecks 2 statements, if both are true then it returns true.a and b
orChecks 2 statements, if one of them is true then it returns true.a or b
notChecks 2 statements, If the result is true then it returns false (reverse).not (a and b)

Identity Operators


Name and SyntaxDescriptionExample
isChecks 2 objects, returns true if they are the same.a is b
is notChecks 2 objects, returns true if they are NOT the same.a is not b

Membership Operators


Name and SyntaxDescriptionExample
inChecks 2 objects, returns true if a sequence with the same value is present in both objects.a in b
not inChecks 2 objects, returns false if a sequence with the same value is present in both objects.a not in b

Binary Comparison Operators (Bitwise)


NameSyntax in PythonExample
AND&a & b
OR|a | b
XOR^a ^ b
NOT~a ~ b
Left Shift<<a << b
Right Shift>>a >> b