why do we invoke print after importing print_function (in Python 2.6)

前端 未结 6 910
再見小時候
再見小時候 2021-01-01 08:15

To get the 3.0 print function we do the following in Python 2.6:

from __future__ import print_function

But to use the function we invoke pr

6条回答
  •  不知归路
    2021-01-01 09:02

    print_function is a FeatureName not be confused with the print built-in function itself. It is a feature that is available from the future so that you can use the built-in function that it can provide.

    Other Features include:

    all_feature_names = [
        "nested_scopes",
        "generators",
        "division",
        "absolute_import",
        "with_statement",
        "print_function",
        "unicode_literals",
    ]
    

    There are specific reasons as when you migrate your code to next higher version, your program will remain as such as use the updated feature instead of the __future__ version. Also if it were function name or the keyword itself, it may cause confusion to the parser.

提交回复
热议问题