Dec-21-2017, 02:58 PM
Python 2.x defaults to integer division.
Python 3.x uses floating point division.
Since Python 2.2, it has been possible to write code compatible with both Python 2 and 3 by using "from __future__ import division" to change the default behavior to use floating point division and using "//" to get integer division.
Python 3.x uses floating point division.
Since Python 2.2, it has been possible to write code compatible with both Python 2 and 3 by using "from __future__ import division" to change the default behavior to use floating point division and using "//" to get integer division.
$ python Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 3/4 0 $ python3 Python 3.6.3 (default, Oct 3 2017, 21:45:48) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 3/4 0.75 $ python2 Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from __future__ import division >>> 3/4 0.75 >>> 3//4 0 >>>