What does print() function do in Python?

PythonServer Side ProgrammingProgramming

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!")
>>> print(5)

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

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

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

Published on 21-Dec-2017 17:17:48