Worked Examples · Example 5.12
Q.Example 5.12: How will the following expression be evaluated in Python?
15.0 / 4 + (8 + 3.0)
Rajasthan RbseTextbookSubjective· 2mImportance★★★★★est
47% · 23/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 first (8 + 3.0 = 11.0), then the division (15.0/4 = 3.75), then the addition — final value 14.75, a float throughout.
Two concepts combine: precedence with parentheses (brackets first, then / before +) and mixed-type arithmetic — whenever an int meets a float, the int is converted and the result is a float.
>>> 15.0 / 4 + (8 + 3.0)
14.75
Evaluation trace:
| Step | What Python does | Expression becomes | Type note |
|---|---|---|---|
| 1 | Parentheses first: 8 + 3.0 | 15.0 / 4 + 11.0 | int + float → float 11.0 |
| 2 | / has higher precedence than +: 15.0 / 4 | 3.75 + 11.0 | float / int → float 3.75 |
| 3 | The addition | 14.75 | float |
Worth noticing:
15.0 / 4gives 3.75 — and in Python 3 even15 / 4(two ints) would give 3.75, because/is true division. Only//floors. …
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.