Python print() Method

The print() method prints the given object to the console or to the text stream file.

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


  1. objects: One or more objects to be printed, seperated by a space ' ' by default.
  2. Sep: (Optional) If multiple objects passed, they are separated by the specified separator. Default is ' '.
  3. end: (Optional) The last value to print. Default is '\n'.
  4. file: (Optional) Must be an object with write(string) method. Default is sys.stdout.
  5. flush: (Optional) The stream is forcibly flushed if buffered. Default is False.

Return Value:

No return value.

The following example prints various objects.

print("Learning Python")
name = 'John'
print("My name is",name)
Learning Python
My name is John

We can pass various parameters to alter the output.

name = 'John'
print("My name is",name,sep='---',end = "\n\n\n\n")
print("I am 18 years old")
My name is---John
I am 18 years old

The following prints the object to the file.

printtofile = open('debug.txt', 'w')
print('printing to file', file = printtofile)
Want to check how much you know Python?