Skip to content
Worked Examples · Example 5.11

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

Uttarakhand UbseTextbookSubjective· 2mImportance★★★★★est
43% · 21/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 →

Parentheses outrank every operator: (20 + 30) is computed first, giving 50, then 50 * 40 = 2000 — the opposite grouping of Example 5.9's 1220.

The concept: parentheses sit at the top of the precedence table. Whatever is inside them is evaluated first, letting the programmer override the default order (where * would beat +).

>>> (20 + 30) * 40
2000

Evaluation trace:

StepWhat Python doesExpression becomes
1Evaluate the parenthesised sub-expression 20 + 3050 * 40
2Perform the multiplication2000

The instructive comparison is with Example 5.9 — the same numbers and operators, different grouping:

ExpressionGroupingResult
20 + 30 * 4020 + (30*40) — precedence rules1220
(20 + 30) * 40forced by parentheses2000

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.