What does print() function do in Python?



In Python 3, print() is a built-in function (object) that is used to print the argument we give it to the screen. For example,

>>> print("Hello!")
Hello!
>>> print(5)
5

Before this, print was a statement. It could be used in the following way:

>>> print "Hello!"
Hello!
>>> print 5
Hello

It evaluates each expression in turn and writes the resulting object to standard output. If an object is not a string, it is first converted to a string using the standard rules for string conversions. The (resulting or original) string is then written to the screen. You can read more about why the print statement was converted to a function in Python 3 here: https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function


Advertisements