All lessons

Numbers & Math

6 min · Python

Use Python as a calculator — and do math with your variables.

Python is a calculator. If you print a math expression, it works out the answer first and prints the result.

Run this — notice it prints 5, not the text 2 + 3, because there are no quotes around it.

Try it yourself

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to run itExpected output: 5

Operators and variables together

The basic operators are + (add), - (subtract), * (multiply), and / (divide). They work on variables too, which is where math gets useful: store the parts, then combine them.

Try it yourself

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to run itExpected output: 15

Your turn

Print the result of 12 multiplied by 12.

Your turn

Loading editor...

Ln 1, Col 1Spaces: 4