Python: Mathematical Order of Operations

Go to Chapter 7 of A Smarter Way.

Note the example:

total_cost = 1 + 3 * 4

You’ll recall from grade school that in equations like this, multiplication (or division) is done first, then addition (or subtraction).

To change this, use parentheses (parens):

total_cost = 1 + (3 * 4)

You can embed parens inside other parens, too:

total_cost = ((2 * 4) * 4) + 2

Exercise

Go to http://www.asmarterwaytolearn.com/python/7.html and review the exercises.