Skip to content
Worked Examples · Example 5.10

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

Rajasthan RbseTextbookSubjective· 2mImportance★★★★★est
39% · 19/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 →

  • 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:

StepWhat Python doesExpression becomes
1Same precedence → take the leftmost first: 20 - 30−10 + 40
2Then the next operator30

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.