Today, when I was studying Python Cookbook, I found a syntax from _ future _ import division, which is very strange. I searched the internet for the name of _ future, it turns out to be a very useful module.
For more information, see here. According to the official explanation, at least ensure that Python versions earlier than 2.1 can run some new language features normally. You need to use the statement 'from _ ure _ import *'. For example:
# Enable nested scopes in Python 2.1.
From _ future _ import nested_scopes
If you use this statement, it must be the first statement of the module or program. In addition, the features in the '_ ure _' module will eventually become part of the Python language standard. By that time, the '_ future _' module will no longer be required.
More examples:
1. There is also a _ ure _ import in Python 2.6 to convert all string texts into Unicode strings. This means that the \ u escape sequence can be used to contain Unicode characters.
From _ future _ import unicode_literals
S = ('\ u751f \ u3080 \ u304e \ u3000 \ u751f \ u3054'
'\ U3081 \ u3000 \ u751f \ u305f \ u307e \ u3054 ')
Print len (s) #12 Unicode characters
2. Python 2.6 can use import _ ure _ to remove print from the language syntax so that you can use the function form. For example:
From _ future _ import print_function
Print ('# of entries', len (dictionary), file = sys. stderr)
3. Integer Division
Python 2.5: 23/6 # Get 3
After from _ future _ import division:
23/6 # Get 3.8333333333333335