What do 7 / 2 and 7 // 2 return in Python 3?
Options
- 3 and 3
- 3.5 and 3 (Correct option)
- 3.5 and 3.5
- 3 and 3.5
Answer
3.5 and 3
Why
/ is normal division and always returns a float (a decimal number): 3.5.
// is floor division: it divides and rounds DOWN to a whole number: 3.
% gives the remainder: 7 % 2 is 1 (useful to check even/odd).
Remember
/ → decimal, // → whole number, % → remainder.