python from __future__ import division

python    from __future__ import division

I have been confused before, why this module is called future, is there any special function that can make people think of the future, I just realized it recently.

        The update and advancement of python is promoted by the community, and it is free and open source, and is not controlled by large commercial companies, so more radical ideas can be quickly used in the update and optimization of new versions of python, which leads to inconvenience Compatibility occurs from time to time. In order to enable people to smoothly transition to the new version, python developers specially provide the __future__ module, so that people can test some features of the new version in the old version. 

The division function in the      __future__ module provides exact division . The following shows the differences in some rules about division through python2.x and python3.x.

In python2.x, there are two cases for division. If it is an integer division, the result is still an integer, and the remainder will be removed. This division is called truncation division.

>>> 5/3
1

Note here that truncation division is not rounding, but directly removing the fractional part.

If you want to do exact division, you must convert one of the numbers to a floating point number:

>>> 5.0/3
1.6666666666666667

In python3.x, all divisions are exact divisions. If you want to use truncation division, you can use "//" to indicate:

>>> 5/3
1.6666666666666667
>>> 5.0/3
1.6666666666666667
>>> 5//3
1

If you want to use exact division and truncation division in python2.x as in python3.x, you can use the division method in the __future__ module to achieve it.

>>> from __future__ import division;
>>> 5/3
1.6666666666666667
>>> 5//3
1