from __future__ import *

Iterations, updates, and changes are all in a developing state

Explain the meaning of the common methods of "_ future _" frequently seen in the code :

Each new version of Python will add some new features, or make some changes to the original features. Some changes are not compatible with the old version, that is, the code that runs normally in the current version may not run properly in the next version.
Python provides the __future__ module to import the features of the next new version into the current version, so we can test some of the features of the new version in the current version.

1. In order to adapt to the new string representation method of Python 3.x, in the code of version 2.7, the new syntax of Python 3.x can be used through unicode_literals, introducing:

from __future__ import unicode_literals

2. Exact division, the result of 2/4 is 0 by default, and the result is 0.5 after importing division

from __future__ import division

3. Absolute import, its function is that if the same module is included in the current project directory when importing a module, the standard library will be imported first. That is to say, if your current directory has a time module, import time will still import Python The official time standard library.

from __future__ import absolute_import

4. Print can be used as a function. The writing format of print in Python2 is print xxx, and in python3 it is print(xxx). Print_function can make python2 use the format of python3.

from __future__ import print_function

Note: In fact, the functions of these three functions are the addition of python2 in order to adapt to the python3 format. If it is python3, it does not need to be imported.

Reference: python , and GolLong .

Guess you like

Origin blog.csdn.net/beauthy/article/details/107565454