In Python, operators are special symbols that perform operations on variables and values. They are the building blocks of expressions, helping you do everything from simple math to complex logical comparisons.

👉 For example:

print(10 + 5)   # Output: 15

Here, + is the addition operator.


Types of Operators in Python

Python groups operators into the following categories:

  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison Operators
  4. Logical Operators
  5. Identity Operators
  6. Membership Operators
  7. Bitwise Operators

1. Arithmetic Operators

Arithmetic operators are used for basic mathematical calculations.

OperatorNameExampleResult
+Addition10 + 515
-Subtraction10 - 55
*Multiplication10 * 550
/Division10 / 52.0
%Modulus10 % 31
**Exponentiation2 ** 38
//Floor Division10 // 33

2. Assignment Operators

Assignment operators are used to assign values to variables, often combining assignment with another operation.

x = 10     # Simple assignment
x += 5     # x = x + 5 → 15
x *= 2     # x = x * 2 → 30

Common assignment operators: =, +=, -=, *=, /=, %=, //=, **=, &=, |=, ^=, >>=, <<=, := (walrus operator).


3. Comparison Operators

Comparison operators compare two values and return a Boolean result (True or False).

print(10 == 10)   # True
print(10 != 5)    # True
print(7 > 3)      # True
print(7 <= 3)     # False
OperatorNameExample
==Equal tox == y
!=Not equal tox != y
>Greater thanx > y
<Less thanx < y
>=Greater than or equal tox >= y
<=Less than or equal tox <= y

4. Logical Operators

Logical operators are used to combine conditional statements.

x = 5
print(x > 3 and x < 10)  # True
print(x > 10 or x == 5)  # True
print(not(x > 3 and x < 10)) # False
OperatorDescriptionExample
andTrue if both conditions are Truex < 5 and x < 10
orTrue if at least one condition is Truex < 5 or x < 4
notReverses the resultnot(x < 5 and x < 10)

5. Identity Operators

Identity operators check if two variables refer to the same object in memory.

a = [1, 2, 3]
b = a
c = [1, 2, 3]

print(a is b)      # True (same object)
print(a is c)      # False (same values, different objects)
print(a is not c)  # True
  • is → True if objects are the same.
  • is not → True if objects are different.

6. Membership Operators

Membership operators test if a value exists inside a sequence (like a string, list, or tuple).

fruits = ["apple", "banana", "cherry"]

print("apple" in fruits)     # True
print("grape" not in fruits) # True
  • in → True if value exists in sequence.
  • not in → True if value does not exist in sequence.

7. Bitwise Operators

Bitwise operators work on the binary representation of numbers.

x = 6   # 110 in binary
y = 3   # 011 in binary

print(x & y)   # 2 (010)
print(x | y)   # 7 (111)
print(x ^ y)   # 5 (101)
print(~x)      # -7 (inverts bits)
print(x << 2)  # 24 (11000)
print(x >> 1)  # 3 (011)
OperatorNameDescription
&ANDSets bit if both are 1
``OR
^XORSets bit if only one is 1
~NOTInverts bits
<<Left shiftShifts bits left
>>Right shiftShifts bits right

Operator Precedence

When multiple operators are used in one expression, Python follows precedence rules (order of execution).

print(100 + 5 * 3)   # 115 (multiplication before addition)
print((100 + 5) * 3) # 315 (parentheses first)

Precedence Order (Highest → Lowest)

  1. () Parentheses
  2. ** Exponentiation
  3. +x, -x, ~x Unary operators
  4. * / // % Multiplication & division
  5. + - Addition & subtraction
  6. << >> Shifts
  7. & Bitwise AND
  8. ^ Bitwise XOR
  9. | Bitwise OR
  10. Comparison, identity, membership
  11. not
  12. and
  13. or

Real-World Applications of Operators 🚀

  • Arithmetic → Finance calculators, scientific computation
  • Comparison & Logical → Decision-making in AI models
  • Assignment → Loop counters, updating variables
  • Identity & Membership → Checking database records or cache
  • Bitwise → Image processing, cryptography, compression

Quick Recap

✔️ Operators are used for calculations, comparisons, logic, and more.
✔️ Python has 7 groups of operators.
✔️ Precedence defines the execution order in complex expressions.
✔️ Mastering operators helps you write faster, smarter, and cleaner code.


👉 At GoNimbus, we help learners go beyond just syntax — we show real-world use cases of Python operators so you can apply them confidently in coding projects.


Scroll to Top