Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 01

What Are Operators and Expressions?

Learn what an operator is, how expressions are formed, and the seven operator families using visual references and real Python examples.

Beginner12 min

What you'll learn

  • What an operator is
  • What an expression is
  • The seven operator families
  • Why Python has no ++ operator

1. What is an operator?

An operator is a symbol that tells Python to perform an action on values, variables, or objects.

Visual analogy: calculator

Simple calculator keypad — numbers plus an operator button

Think of a calculator: the numbers already exist; the + button tells the calculator what action to perform. Python operators work the same way.

Python example

python
a = 10
b = 3

print(a + b)
text
13

How Python sees it

10 plus 3 evaluates to 13

Operator = + → tells Python to add two values.

2. What is an expression?

An expression is a combination of values, variables, or objects connected by operators that Python can evaluate.

Visual flow

Variables and expression a + b evaluate to 13

Code

python
a = 10
b = 3

result = a + b
print(result)

The expression is a + b. The result is 13.

3. The seven operator families

Connect each family to a purpose — not just a symbol.

1. Arithmetic operators

Perform mathematical calculations.

python
10 + 3
10 * 3

Think: calculator

2. Assignment operators

Store values inside variables.

python
age = 25
age += 1

Think: put a value into a labeled box

3. Relational operators

Compare two values; result is True or False.

python
10 > 3

Think: compare two sides of a scale

4. Logical operators

Combine multiple conditions.

python
age > 18 and score > 50

Think: decision making

5. Bitwise operators

Work directly with binary representations of integers.

python
5 & 3

Think: low-level bit patterns (hardware-style logic)

6. Membership operators

Check whether a value exists inside a collection.

python
"Y" in "PYTHON"

Think: search inside

7. Identity operators

Check whether two names refer to the same object in memory.

python
x is y

Think: same memory object, not just equal values

4. Operator mind map

Mind map of Python operator families

This is the classification you will use throughout the rest of this module.

Later you will also see Python’s if ... else expression form (ternary) — it is not a separate symbol family like + or and, but it is the Python way to choose between two values.

5. Membership vs identity (most confusing pair)

Membership → “Is it inside?”

python
print("Y" in "PYTHON")
text
True

Python searches inside the string "PYTHON".

Identity → “Is it the same object?”

x and y pointing to the same list object in memory
python
x = [1, 2]
y = x

print(x is y)
text
True

Both variables point to the same memory object, not just equal values.

Easy memory trick

Operator Meaning
in Search inside a collection
is Check identity (same object)

6. What Python does not support

Python intentionally avoids some operators found in C, C++, Java, and C#.

Not supported (C / C++ / Java style)

text
a++
--b
x ? y : z

These produce syntax errors in Python.

Python alternatives

python
a += 1
b -= 1

y if x else z

Readable, explicit syntax.

C/Java vs Python operator alternatives

7. Interactive playground

Run the code in Try it in the playground at the bottom of this lesson. Identify which operator family each line uses.

Expected output

text
Expression a + b: 13
Relational: True
Logical: True
Membership: True
Identity (same object): True

Identify the family

Code Family
a + b Arithmetic
a > b Relational
and Logical
"Y" in "PYTHON" Membership
x is y Identity

Practice exercises

Exercise 1 — Write an arithmetic expression that multiplies 8 and 5, then adds 2:

python
# Your code here
print(8 * 5 + 2)

Exercise 2 — Without looking above, write the seven operator families in order.

Exercise 3 — Predict before running:

python
a = 5
a++

Invalid — a++ is not valid Python. Use a += 1 instead.

Quick knowledge check

  1. What is an operator?
    A symbol that performs an operation on values, variables, or objects.

  2. What is an expression?
    Values, variables, or objects connected by operators that Python evaluates.

  3. Does Python support ++?
    No. Use += 1 instead.

Summary cheat sheet

Concept Remember
Operator A symbol that performs an action
Expression Values connected by operators
Arithmetic Calculator
Assignment Store value
Relational Compare values
Logical Combine conditions
Bitwise Binary operations
Membership Search inside
Identity Same object in memory

Next lesson: Arithmetic Operators — +, -, *, /, //, %, ** with step-by-step examples.

Loading playground…