Skip to content
Worked Examples · Example 5.9

Q.Example 5.9: How will Python evaluate the following expression?
20 + 30 * 40

Puducherry CbseNCERTSubjective· 2mImportance★★★★★est
35% · 17/49 Questions
🔒 Locked · start free trial →

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:

StepWhat Python doesExpression becomes
1Spot the highest-precedence operator: *20 + (30 * 40)
2Compute 30 * 4020 + 1200
3Compute the addition1220

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.