Operators in Python

Python 8 min min read Updated: Mar 09, 2026 Beginner
Operators in Python
Beginner Topic 5 of 10

Python Operators

Operators are special symbols in Python that are used to perform operations on variables and values. They allow programmers to perform calculations, compare values, combine conditions, and manipulate data efficiently.

For example, when we add two numbers together using the + symbol, Python performs an arithmetic operation.

python x = 10 y = 5 result = x + y print(result)

In the example above, the + operator adds two numbers and produces the result.

Python supports several types of operators, each designed for a specific purpose.

Types of Operators in Python

  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • Assignment Operators
  • Bitwise Operators
  • Membership Operators
  • Identity Operators

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations such as addition, subtraction, multiplication, and division.

Operator Description Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ Division a / b
% Modulus (remainder) a % b
** Exponentiation a ** b
// Floor Division a // b
python a = 10 b = 3 print(a + b) print(a - b) print(a * b) print(a / b) print(a % b) print(a ** b) print(a // b)

Comparison Operators

Comparison operators are used to compare two values. They return either True or False.

Operator Description
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
python x = 10 y = 20 print(x == y) print(x != y) print(x > y) print(x < y)

Logical Operators

Logical operators are used to combine conditional statements.

Operator Description
and Returns True if both conditions are true
or Returns True if at least one condition is true
not Reverses the result
python age = 25 salary = 40000 print(age > 18 and salary > 30000) print(age > 18 or salary > 50000) print(not(age > 30))

Assignment Operators

Assignment operators are used to assign values to variables.

Operator Example
= x = 5
+= x += 3
-= x -= 3
*= x *= 3
/= x /= 3
python x = 10 x += 5 print(x) x *= 2 print(x)

Bitwise Operators

Bitwise operators work on binary numbers and perform bit-level operations.

Operator Description
& AND
| OR
^ XOR
~ NOT
<< Left Shift
>> Right Shift
python a = 5 b = 3 print(a & b) print(a | b) print(a ^ b)

Membership Operators

Membership operators check whether a value exists within a sequence such as a list, tuple, or string.

Operator Description
in Returns True if value exists
not in Returns True if value does not exist
python numbers = [1, 2, 3, 4] print(3 in numbers) print(10 not in numbers)

Identity Operators

Identity operators compare the memory location of two objects.

Operator Description
is Returns True if both variables refer to the same object
is not Returns True if both variables refer to different objects
python x = [1, 2, 3] y = x z = [1, 2, 3] print(x is y) print(x is z)

Conclusion

Operators are an essential part of Python programming because they allow us to perform calculations, comparisons, and logical operations easily. Python provides different types of operators for mathematical operations, logical conditions, bitwise manipulation, and data comparison.

Understanding how operators work will help you write efficient programs and implement complex logic in your applications.

In the next tutorial, we will learn about Python Input and Output and understand how Python interacts with users.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators