Q.How will Python evaluate the following expression?
20 + 30 * 40
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 →Python evaluates 20 + 30 * 40 as 20 + (30 * 40) because multiplication has higher precedence than addition, giving 1220.
This is a classic operator precedence question. The key idea is that Python, like standard mathematics, does not simply evaluate expressions left-to-right. Instead, it follows a strict hierarchy of operators — multiplication (*) sits above addition (+) in that hierarchy.
So when Python sees 20 + 30 * 40, it first groups the multiplication: 30 * 40 is computed as 1200. Only then does it add the 20, giving 1220.
If you wanted the addition to happen first, you would need parentheses: (20 + 30) * 40 would give 50 * 40 = 2000. Without them, multiplication wins. …
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.