3.1.1. Arithmetic operations#
Any arithmetical operation is performed simply by writing its equation. For example, the most usual arithmetic operators are +
, -
, *
, /
and **
. We use parentheses ()
for operation priority.
Addition
4 + 3
Subtraction
4 - 3
Multiplication
4 * 3
Division
4 / 3
Exponent
To raise a value to a power (e.g., to calculate \(4^2\)), we would write:
4 ** 2
Root
For roots, we can exponentiate to the inverse. For example, to calculate \(\sqrt{4}\), we would write:
4 ** (1 / 2)
As an exercise, type one line in the console that performs this operation:
\[\left( \frac{3+5}{6-4} \right)^2\]
Show code cell content
((3 + 5) / (6 - 4)) ** 2
16.0