Numeric expressions
Arithmetic operators combine numbers into expressions, such as a total price.
Maya's receipt shows three items at $4 each and one $2 fee. She wants Python to work out the whole charge in a single line. How can one calculation get it right?
5 minutes. No sign-up needed.
What you'll learn5 ideas
- A numeric expression is a calculation written with numbers, like
3 * 4, which Python turns into12. - Python multiplies with
*, subtracts with-and divides with/, and/always gives a decimal answer like4.5or4.0. - Python's order of operations does multiplying and dividing before adding and subtracting, so
5 + 2 * 6gives17. - When dividing and multiplying sit side by side, Python works from left to right, so
18 / 3 * 2gives12.0. - Python works out what's inside parentheses first, so
(5 + 2) * 6gives42.