Why is print not a function in python?

前端 未结 6 1997
情深已故
情深已故 2021-02-13 13:21

Why is print a keyword in python and not a function?

6条回答
  •  长情又很酷
    2021-02-13 13:36

    print was a statement in Python because it was a statement in ABC, the main inspiration for Python (although it was called WRITE there). That in turn probably had a statement instead of a function as it was a teaching language and as such inspired by basic. Python on the other hand, turned out to be more than a teaching language (although it's good for that too).

    However, nowadays print is a function. Yes, in Python 2 as well, you can do

    from __future__ import print_function
    

    and you are all set. Works since Python 2.6.

提交回复
热议问题