2.7. Order of operations

When more than one operator appears in an expression, the order of evaluation depends on the rules of precedence. For mathematical operators, Python follows mathematical convention. The acronym PEMDAS is a useful way to remember the rules:

Try running the code below as is, then add parentheses around 4 + -2 to see how the order of operations changes.

When in doubt, always put parentheses in your expressions to make sure the computations are performed in the order you intend.

Put these code blocks in the oder that they would run using the order of operations.

You have attempted of activities on this page