I understand what print
does, but of what "type" is that language element? I think it's a function, but why does this fail?
>>> print print SyntaxError: invalid syntax
Isn't print
a function? Shouldn't it print something like this?
>>> print print <function print at ...>
Python print() Function The print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen.
In Python, the print() function is used to get the output and debug the code. This function is used to display the specified message or value in the console. The message can be a string or any other object.
print(): print() method in Java is used to display a text on the console. This text is passed as the parameter to this method in the form of String. This method prints the text on the console and the cursor remains at the end of the text at the console.
In many programming languages, print is a function that sends text, variables, or another object to the screen. If you're more familiar with the programming language Scratch, print is equivalent to say. Below is an example of "Hello World!" getting print to the screen in Perl.
In 2.7 and down, print
is a statement. In python 3, print
is a function. To use the print function in Python 2.6 or 2.7, you can do
>>> from __future__ import print_function >>> print(print) <built-in function print>
See this section from the Python Language Reference, as well as PEP 3105 for why it changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With