Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Function

print

Writes zero or more objects to a text stream, separating them with sep and ending with end. The destination and flushing behavior can be customized with keyword-only arguments.

How it works

Call print() with zero or more objects. Python converts the objects for text output, joins them with sep, appends end, and writes the result to file; flush=True requests an immediate flush of that stream.

Syntax

print(*objects, sep=' ', end='\n', file=None, flush=False)

Parameters

NameTypeDescription
*objectsobjectObjects to convert and write; any number may be supplied.
sepstr or NoneText inserted between objects; defaults to a single space.
endstr or NoneText appended after the final object; defaults to a newline.
fileobject with write method or NoneText stream receiving the output; defaults to standard output.
flushboolWhether to flush the output stream immediately; defaults to False.

Returns

Returns None.

Key points

  • print() writes its objects to a text stream, places sep between them, and appends end.
  • The separator, terminator, destination stream, and flushing option are keyword-only arguments.
  • print() is a built-in function, so ordinary Python code can use it without importing a module.

Common mistakes

  • The formatting and output-stream options are keyword-only; pass them by name rather than position.

Example: Custom separator

print("status", 200, sep=": ", end="\n")

Prints two values with a custom separator and the default line ending.

When to use it

Console output

Display status, results, or diagnostic information during a script run.

Formatted output

Control spacing or line endings when composing text output.

Stream output

Send output to a writable text stream instead of standard output.

  • str()
  • repr()
  • input()
  • sys.stdout

Source: Built-in Functions — Python 3.16.0a0 documentation. Checked 2026-10-15.