PCEP-30-02 · Question #65
What will be the output of the following code snippet? print(3 / 5)
The correct answer is C. 0.6. In Python 3, the / operator always performs true division, returning a float - so 3 / 5 evaluates to 0.6 (option C). Option B (0) would be the result of integer (floor) division, which requires the // operator (3 // 5 == 0); this was the default behavior of / in Python 2, a…
Question
Options
- ANone of the above.
- B0
- C0.6
- D6/10
How the community answered
(38 responses)- A11% (4)
- B5% (2)
- C82% (31)
- D3% (1)
Explanation
In Python 3, the / operator always performs true division, returning a float - so 3 / 5 evaluates to 0.6 (option C). Option B (0) would be the result of integer (floor) division, which requires the // operator (3 // 5 == 0); this was the default behavior of / in Python 2, a common source of confusion. Option D (6/10) is not a valid Python output - Python evaluates the expression and prints the numeric result, never the unsimplified fraction. Option A is incorrect because C is definitively correct.
Memory tip: In Python 3, think of / as "always float" - if you want whole-number division, you need the double slash //. The extra slash "cuts off" the decimal.
Community Discussion
No community discussion yet for this question.