The above behavior is true for Python 2. The behavior has /been fixed in Python 3. In Python 2, you can use:
from __future__ import division
and then use /to get the desired result.
>>> 5 / 2
2
>>> from __future__ import division
>>> 5 / 2
2.5
Since you divide two integers, you get the result as an integer.
Or change one of the numbers to float.
>>> 5.0 / 2
2.5
source
share