🧮 Python Operators Explained with Examples (Beginner Friendly Guide)

Python Operators 

Now that you understand Python variables and data types, it’s time to learn how to work with them. Storing data is useful — but the real power of programming comes when you start performing operations on that data.

This is where Python operators come in.

Operators allow you to:

  • Perform calculations

  • Compare values

  • Combine conditions

  • Assign new values

  • Check logical conditions

In this lesson, you’ll learn all major Python operators with simple examples and real-life explanations.

operators in pythons(image Credit:-Greeksforgreeks



What Are Operators in Python?

An operator is a symbol that performs an operation on variables and values.

For example:

a = 10
b = 5

print(a + b)

Here, + is an operator that adds two numbers.

Output:

15

Simple, right? Let’s explore all types step by step.


Arithmatical Operation (Image Credit :- the knowledge Academy)

1️⃣ Arithmetic Operators (Math Operations)

These operators are used for mathematical calculations.

OperatorMeaningExample
+Addition5 + 3
-Subtraction5 - 3
*Multiplication5 * 3
/Division10 / 2
%Modulus (remainder)10 % 3
**Exponent (power)2 ** 3
//Floor division10 // 3

Example Program:

a = 10
b = 3

print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Remainder:", a % b)
print("Power:", a ** b)
print("Floor Division:", a // b)

Real-Life Example

Imagine you're building a shopping bill calculator:

  • + adds item prices

  • - applies discounts

  • % calculates tax percentage

  • // calculates number of full boxes

Arithmetic operators are used everywhere!


2️⃣ Comparison Operators (Relational Operators)

These operators compare two values and return True or False.

OperatorMeaning
==Equal to
!=Not equal
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal

Example:

x = 10
y = 5

print(x == y) # False
print(x != y) # True
print(x > y) # True
print(x < y) # False

These are very important in decision-making (if-else statements).


3️⃣ Logical Operators

Logical operators are used to combine multiple conditions.

OperatorMeaning
andTrue if both conditions are true
orTrue if at least one condition is true
notReverses the result

Example:

age = 20
has_id = True

print(age >= 18 and has_id) # True
print(age < 18 or has_id) # True
print(not has_id) # False

Real-Life Example:

Checking if someone can vote:

  • Age must be 18+

  • Must have ID

Logical operators make such checks possible.


4️⃣ Assignment Operators

Assignment operators assign values to variables.

OperatorExampleMeaning
=x = 5Assign value
+=x += 3x = x + 3
-=x -= 2x = x - 2
*=x *= 4x = x * 4
/=x /= 2x = x / 2

Example:

x = 10
x += 5
print(x) # 15

x *= 2
print(x) # 30

These make code shorter and cleaner.


5️⃣ Identity Operators

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

OperatorMeaning
isTrue if same object
is notTrue if not same object

Example:

a = 5
b = 5

print(a is b) # True

Used more in advanced Python concepts.


6️⃣ Membership Operators

These check whether a value exists inside a sequence (like list, string, tuple).

OperatorMeaning
inTrue if value exists
not inTrue if value does not exist

Example:

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

print("apple" in fruits) # True
print("grapes" not in fruits) # True

Very useful when working with lists and strings.


Mini Project: Simple Login Checker

Let’s combine operators in a small program:

username = "admin"
password = "1234"

input_user = input("Enter username: ")
input_pass = input("Enter password: ")

if input_user == username and input_pass == password:
print("Login Successful!")
else:
print("Invalid Credentials!")

Here we used:

  • Comparison operators (==)

  • Logical operator (and)

  • Conditional statement (if-else)

This is how real applications work!


Common Beginner Mistakes

❌ Using = instead of == in comparisons
❌ Forgetting operator priority
❌ Mixing data types (like string + number without conversion)

Example mistake:

age = "18"
print(age + 2) # Error

Correct way:

age = int("18")
print(age + 2)

Operators and expression of python(image credit :- Real Python)

Operator Precedence (Order of Operations)

Python follows a specific order:

  1. Parentheses ()

  2. Exponent **

  3. Multiplication/Division

  4. Addition/Subtraction

  5. Comparison

  6. Logical operators

Example:

result = 10 + 5 * 2
print(result) # 20 (not 30)

Because multiplication happens first.


Conclusion

Python operators are the engine of programming logic. They allow you to:

  • Perform calculations

  • Compare values

  • Combine conditions

  • Assign and modify data

  • Build real-world applications

Once you master operators, you are ready to move to the next powerful concept — Conditional Statements (if, elif, else).

Keep practicing small programs daily — that’s the secret to mastering Python. 🚀


 What is python

Python course

Python Variables and Data Types


Comments

AI and the Future of Finance: How Artificial Intelligence is Transforming Money Management

2025's Best Free AI Financial Tools | Smart Money Apps

AI and the Future of Finance: How Artificial Intelligence is Transforming Money Management