Print() in python

Python print() function prints the message to the screen or any other standard output device. In this article, we will cover about print() function in Python as well as it’s various operations.

# print() function example
print("hello world")

a = [1, 2, 'gfg']
print(a)

Syntax of print function

Syntax: print(value(s), sep= ‘ ‘, end = ‘\n’, file=file, flush=flush)**

Parameters:

  • value(s): Any value, and as many as you like. Will be converted to a string before printed

  • sep=’separator’ : (Optional) Specify how to separate the objects, if there is more than one.Default :’ ‘

  • end=’end’: (Optional) Specify what to print at the end.Default : ‘\n’

  • file : (Optional) An object with a write method. Default :sys.stdout

  • flush : (Optional) A Boolean, specifying if the output is flushed (True) or buffered (False). Default: False

    Return Type: It returns output to the screen.

Examples

print ("python is easy to code")

# print() function ends with "**" as set in end parameter.
print ("python is easy to code", end= "**")

# sep = -
a = 12
b = 12
c = 2022
print(a, b, c, sep="-")
print('Welcome to Python world', file=open('Testfile.txt', 'w'))