如何使python2.7的程序与python3.x的兼容

来源:互联网 发布:董秘助手软件 编辑:程序博客网 时间:2024/06/05 13:33

We encourage you to place the following statement at the start of your programs, in order that your program will run not only on Python 2.7 today, but also will run in the future on the newer Python 3.x series. Note the double underscore before “future” and the double underscore after “future”.

from _future_ import print_function, division

For Python 2.7, this statement invokes the new Python 3.x print format, namely “print(x)” instead of the old “print x”, and the new division scheme, namely that 3/4 is 0.75, not zero as in the past. This statement is ignored by Python 3.x.

0 0
原创粉丝点击