1.6. Operator Precedence#
What is 8/2(2+2)
?
PEMDAS: “Please Excuse My Dear Aunt Sally”
Order of Precedence:
P – Parentheses
E – Exponents
MD - Multiplication and Division (left to right)
AS – Addition and Subtraction (left to right)
Precedence in Python:
Parentheses
Exponents
Unary plus, Unary minus
Multiplication, Division, Integer division, Modulus (Remainder)
Addition, Subtraction
What is incorrect with the following expression? 212 - 32 * 5 / 9
It’s advisable to use parentheses to clarify complex expressions, even when they aren’t necessary for intent, as this practice enhances code readability.