Programming Fundamentals · Lesson 04
Expressions and operators
Combine values into calculations and control the order of operations.
An expression is a combination of values, names, and operators that produces a value. Addition uses +, subtraction uses -, multiplication uses *, and division uses /.
Python follows an order of operations. Multiplication and division happen before addition and subtraction. Parentheses let you group the part of a calculation that should happen first.
Suppose a workshop has a fixed delivery charge and a price per kit. Trace the expression by substituting the values for their names before doing the arithmetic.
Read the example
kits = 3
price = 40
delivery = 10
print(kits * price + delivery)
print(kits * (price + delivery))
130 150
The first calculation adds one delivery charge to the price of three kits. The second adds delivery to each kit before multiplying. The parentheses change the meaning of the calculation.
Try it yourself
A group buys four kits at 50 each and uses a discount of 20 on the whole order. Write an expression for the total and check it by hand.
Show a worked solution
kits = 4
price = 50
discount = 20
print(kits * price - discount) # 180
Check your understanding
Your lesson quiz
Answer all five questions. Score at least 4 out of 5 (80%) to pass. You can retry as often as you like.
Quiz progress is saved in this browser. View certificates →
Learn together
Was this lesson helpful?
Comments and reactions are not open yet.
Join the conversation
Ask a question or share what you learned. Your display name and comment will be public after review. Please leave out private information. How feedback is stored