Operators Percedence and Associativity
M3-R5.1 · Chapter 4: Operators, Expressions and Python Statements · 3 min read
Operator Percedence & Associativity
When Python sees an expression like 3 + 4 * 2, it doesn't just go left to right — it decides which operation to do first based on a set of rules called operator precedence.
Operators with higher precedence are evaluated first.
Associativity tells Python what to do when two operators have the same precedence — whether to go left-to-right or right-to-left.
Precedence table (high → low)
|
Python Operators Precedence Rule – PEMDAS
We might have heard about the BODMAS rule in your school’s mathematics class. Python also uses a similar type of rule known as PEMDAS.
The precedence of operators is listed from High to low.
To remember the abbreviations, we have a funny concept “Please Excuse Me Dear Aunt Sally
Now we apply the PEMDAS rule and evaluate the following expression –
Let Evaluate - ((((6+4)*2)-10)//2)-4*2
Some Practice Questions -
Q1 - 3 + 5 * 2
Q2 - 10 - 4 + 2
Q3 - 2 ** 3 ** 2
Q4 - 20 // 3 % 2 + 1
Q5 - 2 ** 2*2**3
Q6 -True + 3 * 2 == 7
Q7 - not 5 > 3 and 2 < 4
Q8 - 3 + 2 ** 2 * 4 - 8 // 3
Q9 - ((3 + 2) ** 2 - 4 * 3) // (7 % 4)
Q10 - 5 + 3 > 2 * 4 or not 10 // 3 == 3