Worked Examples · Example 5.11
Q.Example 5.11: How will Python evaluate the following expression?
(20 + 30) * 40
Telangana TsbieTextbookSubjective· 2mImportance★★★★★est
43% · 21/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 →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:
| Step | What Python does | Expression becomes |
|---|---|---|
| 1 | Evaluate the parenthesised sub-expression 20 + 30 | 50 * 40 |
| 2 | Perform the multiplication | 2000 |
The instructive comparison is with Example 5.9 — the same numbers and operators, different grouping:
| Expression | Grouping | Result |
|---|---|---|
| 20 + 30 * 40 | 20 + (30*40) — precedence rules | 1220 |
| (20 + 30) * 40 | forced by parentheses | 2000 |
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.