Module 2 · Operators · Lesson 1 of 4
Python as a calculator
There's a side of print you haven't seen yet. So far you've passed it finished values — but you can also pass it an expression, and Python will work out the answer before printing it.
Run it yourselfruns in your browser · Python
main.py
Run it. You don't get the text 2 + 2 — you get 4. Python evaluated the expression inside the parentheses first, then handed the result to print.
It works the answer out first
print(2 + 2)Python evaluates 2 + 2 ↓
4
4
…so print shows the value, not the text “2 + 2”.That little + is an operator, and 2 + 2 is an expression — data joined together by operators. The simplest expression of all is just a single literal. From here on we're in the territory of operators and expressions, and the next lesson goes through the tools one by one.