Why is print not a function in python?

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

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

6条回答
  •  清酒与你
    2021-02-13 13:38

    An answer that draws from what I appreciate about the print statement, but not necessarily from the official Python history...

    Python is, to some extent, a scripting language. Now, there are lots of definitions of "scripting language", but the one I'll use here is: a language designed for efficient use of short or interactive programs. Such languages tend to allow one-line programs without excessive boilerplate; make keyboard input easier (for instance, by avoiding excessive punctuation); and provide built-in syntax for common tasks (convenience at the possible expense of purity). In Python's case, printing a value is a very common thing to do, especially in interactive mode. Requiring print to be a function seems unnecessarily inconvenient here. There's a significantly lower risk of error with the special syntax that does the right thing 99% of the time.

提交回复
热议问题