Worked Examples · Example 3.7
Q.How will the following expression be evaluated?
15.0 / 4.0 + (8 + 3.0)
Sikkim CbseNCERTSubjective· 2mImportance★★★★★est
28% · 7/25 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 →This expression evaluates to 14.75 by applying operator precedence: parentheses first, then division (left-to-right), then addition.
Why operator precedence matters
When Python (or any programming language) encounters an expression with multiple operators, it doesn't simply evaluate left-to-right. Instead, it follows a strict hierarchy called operator precedence that determines which operations execute first. Think of it as the mathematical order of operations (PEMDAS/BODMAS) built into the language.
The precedence rules relevant here are:
- Parentheses
( )— highest priority; always evaluated first - Multiplication
*, Division/, Floor Division//, Modulus%— equal priority among themselves, evaluated left-to-right - Addition
+, Subtraction-— lower priority, also left-to-right
Step-by-step evaluation
Let's trace through 15.0 / 4.0 + (8 + 3.0):
| Step | Expression | Operation | Result |
|---|---|---|---|
| 1 | 15.0 / 4.0 + (8 + 3.0) | Evaluate parentheses: 8 + 3.0 | 15.0 / 4.0 + 11.0 |
| 2 | 15.0 / 4.0 + 11.0 | Division (higher precedence than +): 15.0 / 4.0 | 3.75 + 11.0 |
| 3 | 3.75 + 11.0 | Addition | 14.75 |
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.