7 python Operators that you Must Know
Updated Jun 2026 · Tested on Linux, Unix
Python language operators are must for python programmer. Python language is an interpreted, object-oriented and high-level programming language very easy to learn for new python beginners.
In Python, operators are special symbols that perform specific operations on one or more operands (values or variables). Some common types of operators in Python include:
Arithmetic operators
These operators perform basic arithmetic operations, such as addition (+), subtraction (-), multiplication (*), and division (/).
Examples of Arithmetic operators
x = 5y = 2z = x + y # z is 7z = x - y # z is 3z = x * y # z is 10z = x / y # z is 2.5
Assignment operators
These operators assign a value to a variable. The most basic assignment operator is the equal sign (=), which assigns the value on the right to the variable on the left.
Example of Assignment operator
a = 5b = 10c = a + b # c is 15
Comparison operators
These operators compare two values and return a Boolean value indicating whether the comparison is True or False. Some common comparison operators include equal to (==), not equal to (!=), greater than (>), and less than (<).
Example of Comparison operators
d = 5e = 10f = 5print(d == e) # Falseprint(d != e) # Trueprint(d > e) # Falseprint(d < e) # Trueprint(d == f) # True
Logical operators
These operators perform logical operations, such as AND (&&) and OR (||). They are often used in conjunction with comparison operators to create more complex conditions.
Example of Logical operators
g = Trueh = Falseprint(g and h) # Falseprint(g or h) # True
Membership operators
These operators test for membership in a sequence, such as a list or a string. The membership operators are “in” and “not in”.
Example of Membership operator
i = [1, 2, 3, 4, 5]print(3 in i) # Trueprint(6 in i) # False
Identity operators
These operators compare the memory addresses of two objects to determine if they are the same object. The identity operators are “is” and “is not”.
Example of Identity operator
j = [1, 2, 3]k = [1, 2, 3]l = jprint(j is k) # Falseprint(j is l) # True
bitwise operators
In Python, bitwise operators are used to perform operations on the individual bits of an integer value.
# Bitwise AND (&)x = 0b1010 # 10 in binaryy = 0b1100 # 12 in binaryz = x & y # 8 in binary, or 8 in decimalprint(z) # 8
# Bitwise OR (|)x = 0b1010 # 10 in binaryy = 0b1100 # 12 in binaryz = x | y # 14 in binary, or 14 in decimalprint(z) # 14
# Bitwise XOR (^)x = 0b1010 # 10 in binaryy = 0b1100 # 12 in binaryz = x ^ y # 6 in binary, or 6 in decimalprint(z) # 6
# Bitwise NOT (~)x = 0b1010 # 10 in binaryy = ~x # -11 in binary, or -11 in decimalprint(y) # -11
# Bitwise left shift (<<)x = 0b1010 # 10 in binaryy = x << 2 # 40 in binary, or 40 in decimalprint(y) # 40
# Bitwise right shift (>>)x = 0b1010 # 10 in binaryy = x >> 2 # 2 in binary, or 2 in decimalprint(y) # 2
Bitwise operators are often used in Python for low-level operations, such as setting or testing individual bits in a value or masking bits .