- Courses
- 💻Programming Languages
- 🐍Python
- Foundations
- Operators and Expressions
On this page
Operators and Expressions
Published on August 17, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
What an Expression Is
An expression is a combination of values, variables, and operators that Python evaluates to produce a result. Every expression has a value. Expressions are the building blocks of all Python programs.
2 + 3
x * 10
"Hello" + "World"
Python evaluates each expression and returns the resulting value.
What an Operator Is
An operator is a symbol that performs an action on one or more values. Operators allow you to compute results, compare values, and build logic. Python includes several categories of operators, each serving a specific purpose.
Arithmetic Operators
Arithmetic operators perform basic mathematical operations.
a = 10
b = 3
print(a + b) # Addition
print(a - b) # Subtraction
print(a * b) # Multiplication
print(a / b) # Division (float result)
print(a // b) # Floor division (integer result)
print(a % b) # Remainder
print(a ** b) # Exponentiation
These operators work with integers, floats, and expressions that evaluate to numeric values.
String Operations
The + and * operators also work with strings.
print("Hello" + " " + "Python") # Concatenation: output is "Hello Python"
print("Hi" * 3) # Repetition: output is "HiHiHi"
These operations are common when formatting output or constructing messages.
Comparison Operators
Comparison operators evaluate relationships between values and return a Boolean (True or False).
x = 5
print(x == 5) # Equal -> True
print(x != 3) # Not equal -> True
print(x > 2) # Greater than -> True
print(x < 10) # Less than -> True
print(x >= 5) # Greater or equal -> True
print(x <= 4) # Less or equal -> False
Comparison results are essential for decision‑making and control flow.
Logical Operators
Logical operators combine Boolean values to form more complex conditions.
is_member = True
has_paid = False
print(is_member and has_paid) # Both must be True
print(is_member or has_paid) # At least one must be True
print(not is_member) # Negation
Logical operators are used extensively in conditional statements.
Assignment Operators
Assignment operators store values in variables. The basic operator is =, but Python also provides compound assignment operators.
x = 10
x += 5 # x = x + 5
x -= 3 # x = x - 3
x *= 2 # x = x * 2
x /= 4 # x = x / 4
Compound assignments make code more concise and readable.
Operator Precedence
When an expression contains multiple operators, Python follows a specific order of evaluation. For example:
result = 2 + 3 * 4
Multiplication happens before addition, so the result is 14, not 20.
Parentheses allow you to control the order explicitly:
result = (2 + 3) * 4 # Now the result is 20
Understanding precedence ensures that expressions behave as intended.
Evaluating Expressions Step by Step
Python evaluates expressions from left to right, applying operator precedence rules. Consider:
x = 10
y = 3
z = x * y + 2
Python performs:
x * y→3030 + 2→32
The final value of z is 32.
Why Operators and Expressions Matter
Operators and expressions allow you to compute results, compare values, and build logic. They appear in every Python program, from simple scripts to complex applications. Mastering them early ensures that later topics—such as conditions, loops, functions, and data structures—will be easier to understand and apply.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Input and Output
Next
Guided Exercise: Build an Interactive Calculator
- What an Expression Is
- What an Operator Is
- Arithmetic Operators
- String Operations
- Comparison Operators
- Logical Operators
- Assignment Operators
- Operator Precedence
- Evaluating Expressions Step by Step
- Why Operators and Expressions Matter
