✦ Python Foundations Third lesson

Concept 03 · Operators

Operators —
Make Python Do Something

Operators let Python calculate, compare values, and combine simple logical ideas. Learn how a few symbols can change what a program does.

01 Learn02 Try03 Predict

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

Operators tell Python what to do with values.

An operator tells Python which operation to perform on one or more values. Building on Variables and Data Types, read a simple expression as value → operator → value → result. Different operators calculate values, ask comparison questions, or combine Boolean results.

10 + 3

Python sees the value 10, the operator +, and the value 3. The + operator tells Python to add the two numbers, so the result is 13. Operators are not just symbols to memorize: each one tells Python how to work with values.

value → operator → value → result 10 → + → 3 → 13

In this lesson, arithmetic operators calculate values, comparison operators produce a bool value, and logical operators combine or change Boolean results. The type of a value still matters: you learned in Data Types that Python can treat numbers and text differently.

↳

Data types still matter: Arithmetic operators in this lesson work with numbers. As you learned in Data Types, the same symbol can behave differently with text, so first notice what type of value Python is working with.

Arithmetic operators calculate with numbers
x = 10
y = 3

print(x + y)   # 13
print(x - y)   # 7
print(x * y)   # 30
print(x / y)   # 3.333...
print(x // y)  # 3
print(x % y)   # 1
print(2 ** 3)  # 8

+, -, and * add, subtract, and multiply. The other arithmetic operators deserve a closer look: / divides, // counts complete groups, % gives the remainder, and ** raises a number to a power.

Division, complete groups, and remainder
print(10 / 2)   # 5.0
print(10 // 3)  # 3
print(10 % 3)   # 1

# 10 = 3 × 3 + 1

number = 8
print(number % 2)  # 0

The / operator performs ordinary division and returns a float, even when the answer looks like a whole number: 10 / 2 is 5.0. With positive numbers, 10 // 3 tells us that three complete groups of three fit into ten, while 10 % 3 gives the remainder, 1. A remainder of 0 means a number divides evenly by 2 — useful later when working with even and odd numbers.

Exponentiation repeats multiplication
print(2 ** 3)  # 8

# 2 ** 3 means 2 × 2 × 2

The ** operator is exponentiation. 2 ** 3 means multiply 2 by itself three times: 2 × 2 × 2, which gives 8.

Comparison operators ask questions
age = 18

print(age == 18)  # True
print(age != 20)  # True
print(age > 20)   # False
print(age >= 18)  # True
print(age < 21)   # True
print(age <= 18)  # True

A comparison operator asks Python a question, such as “Is age greater than or equal to 18?” Its answer is always True or False — a bool value from the Data Types lesson. ==, !=, >, <, >=, and <= all make comparisons.

= assigns; == compares
age = 18      # assign 18 to age

print(age == 18)  # ask whether age equals 18

= assigns a value to a name: age = 18. == asks whether a value is equal: age == 18. Remember: = assigns; == compares.

Logical operators work with Boolean results
age = 20
has_ticket = True
is_raining = False

print(age >= 18 and has_ticket)  # True
print(age < 18 or has_ticket)    # True
print(not is_raining)            # True

and is True when both conditions are True. or is True when at least one condition is True. not reverses a Boolean value: not False becomes True. Think: and means both, or means at least one, and not means the opposite. You will use these ideas in Conditions later.

Parentheses make the intended order clear
print(2 + 3 * 4)    # 14
print((2 + 3) * 4)  # 20

Python does not always evaluate an expression from left to right. Multiplication happens before addition, so 2 + 3 * 4 is 14. Parentheses change the order, so (2 + 3) * 4 is 20. When an expression could be unclear, use parentheses to show your intended order.

Read the code before you run it
score = 12
bonus = 3

print(score + bonus * 2)
print(score >= 10)
print(score >= 10 and bonus > 0)

Pause before running this program. What do you predict? Python first multiplies bonus * 2, then adds it to score, so the first result is 18. The next two lines ask comparison questions; both produce True. Reading expressions step by step helps you understand code instead of only copying it.

Python Playground

Loading Python runtime…

Run the starting code once, then change x and y. Before each run, predict the arithmetic, comparison, and logical results. Use the Learn examples to explain what each operator tells Python to do.

operators.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Think about the remainder left after dividing eight by three.

x = 8
y = 3

print(x % y)
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.