__future__ module with division function
Here we are going to use the division function in Python2.x and Python3.x.
Let’s see the example in Python2.x.
Python
# In 2.7 python compiler print 7 / 5 print - 7 / 5 |
Output:
1.4 -1.4
And let see this with the future module, it will give you the accurate result.
Python
# In below python 2.x code, division works # same as Python 3.x because we use __future__ from __future__ import division print 7 / 5 print - 7 / 5 |
Output:
1.4 -1.4
__future__ Module in Python
__future__ module is a built-in module in Python that is used to inherit new features that will be available in the new Python versions..
This module includes all the latest functions which were not present in the previous version in Python. And we can use this by importing the __future__ module. Its releases are in Python version 2.1. The basic idea of the __future__ module is to help migrate to use Python 3.X features.
Note: The future statements must at the top of the file, otherwise the Python interpreter will raise SyntaxError