Bird
0
0

Why does the expression '5 / 2' return a float but '5 // 2' returns an integer in Python?

hard📝 Conceptual Q10 of 15
Python - Operators and Expression Evaluation
Why does the expression '5 / 2' return a float but '5 // 2' returns an integer in Python?
A'/' always returns float; '//' returns floor integer division
B'/' returns integer; '//' returns float
CBoth return float but formatted differently
DBoth return integer but '//' rounds up
Step-by-Step Solution
Solution:
  1. Step 1: Understand '/' operator behavior

    The '/' operator performs true division and returns a float result.
  2. Step 2: Understand '//' operator behavior

    The '//' operator performs floor division, returning the largest integer less than or equal to the division result.
  3. Final Answer:

    '/' always returns float; '//' returns floor integer division -> Option A
  4. Quick Check:

    / = float division, // = floor integer division [OK]
Quick Trick: Use // for floor division, / for float division [OK]
Common Mistakes:
MISTAKES
  • Thinking // returns float
  • Assuming / returns integer
  • Confusing floor with rounding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes