Python | Output using print() function

The simplest way to produce output is using the print() function where you can pass zero or more expressions separated by commas. This function converts the expressions you pass into a string before writing to the screen.

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 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

Returns: It returns output to the screen.

Code #1: Using print() function in Python(2.x)



filter_none

edit
close

play_arrow

link
brightness_4
code

# Python 2.x program showing
# how to print data on
# a screen
  
# One object is passed
print "GeeksForGeeks"
  
# Four objects are passed
print "Geeks", "For", "Geeks", "Portal"
  
l = [1, 2, 3, 4, 5]
# printing a list
print l

chevron_right


Output:

GeeksForGeeks
Geeks For Geeks Portal
[1, 2, 3, 4, 5]

 
Code #2 : Using print() function in Python(3.x)

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python 3.x program showing
# how to print data on
# a screen
  
# One object is passed
print("GeeksForGeeks")
  
x = 5
# Two objects are passed
print("x =", x)
  
# code for disabling the softspace feature 
print('G', 'F', 'G', sep ='')
  
# using end argument
print("Python", end = '@')  
print("GeeksforGeeks"

chevron_right


Output:

GeeksForGeeks
x = 5
GFG
Python@GeeksforGeeks


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

3


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.