- Use Python's mathematical operators to perform calculations.
- Understand how Python uses the Order of Operations (BEDMAS/PEMDAS).
- Store the result of a calculation in a variable.
Working with Numbers
Python is a fantastic tool for performing mathematical calculations. It uses operators that you are already familiar with, plus a few special ones for programming.
+: Addition-: Subtraction*: Multiplication/: Division (always results in a float, e.g., 10 / 2 is 2.0)**: Exponent (e.g.,2**3is 2 to the power of 3)%: Modulo (gives the remainder of a division, e.g.,10 % 3is 1)
Python automatically follows the standard mathematical Order of Operations (BEDMAS/PEMDAS). You can always use parentheses () to control the order of calculations yourself.
Live Example: The best way to learn is to play!
The code below is a live, interactive calculator. Click the Run â–¶ button to see the results of the calculations. Then, go into the code and change the numbers, add parentheses, or try a different operator. See if you can predict the result before you run it!
You can trust Python to handle math correctly. By combining variables with these mathematical operators, you can make your programs perform powerful and complex calculations.
Interactive Sandbox
Use this space to practice writing code and complete the "Your Turn" activities above.