Professional Documents
Culture Documents
11 - Math Operators
11 - Math Operators
Section 2, Lecture 11
You can perform math operations using Python operators (+, -, *, /, **). The
examples below cover all basic math operators available in Python:
Addition
>>> 1 + 3.5
4.5
Subtraction
>>> 1 - 3.5
-2.5
Multiplication
>>> 1 * 3.5
3.5
Division
>>> 1 / 3.5
0.2857142857142857
Exponentiation (3 * 3 * 3 * 3)
>>> 3 ** 4
81
>>> 1 + 2 * 10**2
201
You get 201 because first we get 100 from 10**2 (exponentiation), and then
we get 200 from 2 * 100 (multiplication), and finally 201 from 1 + 200
(addition).
>>> (1 + 2) * 10**2
300
You get 300 because first we get 3 from 1 + 2, and then we get 100 from
10**2 and then 300 from 3 * 100.