Worked Examples · Example 5.9
Q.Example 5.9: How will Python evaluate the following expression?
20 + 30 * 40
Uttarakhand UbseTextbookSubjective· 2mImportance★★★★★est
35% · 17/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 →Because * outranks + in operator precedence, 20 + 30 * 40 is evaluated as 20 + (30 * 40) = 1220, not left-to-right.
The concept is operator precedence: when an expression mixes operators, Python does not simply work left to right — it applies the higher-precedence operator first. Multiplication and division rank above addition and subtraction, exactly as in school algebra (BODMAS).
>>> 20 + 30 * 40
1220
Evaluation trace:
| Step | What Python does | Expression becomes |
|---|---|---|
| 1 | Spot the highest-precedence operator: * | 20 + (30 * 40) |
| 2 | Compute 30 * 40 | 20 + 1200 |
| 3 | Compute the addition | 1220 |
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.