Worked Examples · Example 5.10
Q.Example 5.10: How will Python evaluate the following expression?
20 - 30 + 40
Yanam CbseNCERTSubjective· 2mImportance★★★★★est
39% · 19/49 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →- and − have equal precedence, so the tie is broken left-to-right: (20 − 30) + 40 = −10 + 40 = 30.
The concept is associativity — the companion rule to precedence. Precedence decides between different operators; when two operators have the same precedence (like - and +), Python evaluates them in order from left to right.
>>> 20 - 30 + 40
30
Evaluation trace:
| Step | What Python does | Expression becomes |
|---|---|---|
| 1 | Same precedence → take the leftmost first: 20 - 30 | −10 + 40 |
| 2 | Then the next operator | 30 |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.