print

Full name
print
Library
Built-in
Syntax

print(*objects, sep = ' ', end = '\n', file = sys.stdout, flush = False)

Description

The print function prints the first argument, objects, in the file channel, using sep as a separator and followed by end. The arguments sep, end, file, and flush, if specified, must be given as keyword arguments.

All arguments that are not specified with a keyword are converted to text strings. Both sep and end must be text strings, although they can also be None, which will mean that the default values are considered.

If no object to print is specified, the function simply prints end.

Whether or not the output is buffered is determined by the file channel, but if the flush argument takes the value True, the buffer is forced to be flushed.

Parameters
  • objects: objects to print.
  • sep: (optional) separator to use between objects. The default is a blank space.
  • end: (optional) text string to print at the end. The default is a newline.
  • file: (optional) channel to use for printing.
  • flush: (optional) boolean that determines whether to force buffer flush.
Examples

The function can print one or more objects simultaneously:

x, y = 1, 2
print(x, y)

Print function. Example of use

 

In this example the objects are separated by a dash:

x, y = 1, 2
print(x, y, sep = "-")

Print function. Example of use

 

Here we use a newline character as a separator:

x, y = 1, 2
print(x, y, sep = "\n")

Print function. Example of use

 

In this example we print the objects with a custom print completion text string:

x, y = 1, 2
print(x, y, end = "*")

Print function. Example of use

 

Finally, we print the objects by customizing the text string to use between them and forcing the buffer to be emptied:

x, y = 1, 2
print(x, y, sep = "*", flush = True)

Print function. Example of use

 

Submitted by admin on Sun, 01/20/2019 - 16:37