Expressions and Values: Arithmetic in Python
You’re familiar with mathematical expressions like 3 + 4 (“three plus four”) and 2 - 3 / 5 (“two minus three divided by five”); each expression is built out of values like 2, 3, and 5 and operators like + and -, which combine their operands in different ways. In the expression 4 / 5, the operator is “/” and the operands are 4 and 5.
Expressions don’t have to involve an operator: a number by itself is an expression. For example, we consider 212 to be an expression as well as a value.
Like any programming language, Python can evaluate basic mathematical expressions. For example, the following expression adds 4 and 13:
| | >>> 4 + 13 |
| | 17 |
The >>> symbol is called a prompt. When you opened ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access