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

前端 未结 6 879
再見小時候
再見小時候 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:04

    In Python 3, the keyword print has been changed from calling a statement to calling a function.

    So instead of saying print value you now need to say print(value), or you'll get a SyntaxError.

    By doing the import, this change is effected in Python 2, too, so you can write programs using the same syntax as Python 3 (at least as far as print is concerned).

提交回复
热议问题