Python - Using print function

Introduction

The following prints a variety of object types to the default standard output stream, with the default separator and end-of-line formatting added:

Demo

print()                                      # Display a blank line 
# w ww  . j a  v a2 s  .co  m
x = 'test' 
y = 99 
z = ['eggs'] 

print(x, y, z)                               # Print three objects per defaults

Result

There's no need to convert objects to strings here, as would be required for file write methods.

By default, print calls add a space between the objects printed.

To suppress this, send an empty string to the sep keyword argument, or send an alternative separator of your choosing:

Demo

x = 'test' 
y = 99 # from w  w w .j  av a  2 s  .c  o m
z = ['eggs'] 

print(x, y, z, sep='')                       # Suppress separator 
print(x, y, z, sep=', ')                     # Custom separator

Result

Related Topic