ScanSkill

print

This print() function returns a printed representation of the objects.

Syntax

print(*objects, sep=’ ‘, end=’n’, file=sys.stdout)

Here,

  • objects: Optional. Objects to be printed.
  • sep: Optional. A string printed between objects. Keyword argument.
  • end: Optional. A string appended to the end of the statement. Keyword argument.
  • file: Optional. An object with write(string) method. Keyword argument.

Note: All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.

This function is not normally available as a built-in since the name print is recognized as the print statement. To disable the statement and use the print() function, use this future statement at the top of your module:

>>> from __future__ import print_function

Examples

>>> from __future__ import print_function
>>> print('a', 'b')
a b
>>> print(1, 2, 3, sep='|')
1|2|3
>>> print('cloudyfox technology', end='|')
cloudyfox technology|
>>> print('cloudyfox', file=open(r'/home/sagar/text.txt', "w"))
>>> open(r'/home/sagar/text.txt', "r").read()
'cloudyfox\\n'