Python print() function (original) (raw)

Last Updated : 17 Nov, 2025

The print() function in Python displays the given values as output on the screen. It can print one or multiple objects and allows customizing separators, endings, output streams and buffer behavior. It is one of the most commonly used functions for producing readable output.

**Example 1: This example prints a list, tuple, and string together using the default separator and ending.

Python `

lst = [1, 2, 3] t = ("A", "B") s = "Python" print(lst, t, s)

`

Output

[1, 2, 3] ('A', 'B') Python

**Explanation: The function prints all objects in one line separated by the default space because sep=" ".

Syntax

print(object(s), sep, end, file, flush)

**Parameters:

**Example 2: This example prints multiple objects but uses a custom separator to control spacing.

Python `

lst = [1, 2, 3] t = ("A", "B") s = "Python" print(lst, t, s, sep=" | ")

`

Output

[1, 2, 3] | ('A', 'B') | Python

**Explanation: The separator " | " replaces the default space, so print() inserts " | " between each object.

**Example 3: This example shows how to print output without moving to the next line by changing the end character.

Python `

lst = [1, 2, 3] t = ("A", "B") s = "Python" print(lst, t, s, end=" --> END")

`

Output

[1, 2, 3] ('A', 'B') Python --> END

**Explanation: The text " --> END" is printed at the end instead of the default newline because of end=" --> END".

**Example 4: This example reads a file and prints its entire content using print().

dfhfgh

notepad

To read and print this content we will use the below code:

Python `

f = open("geeksforgeeks.txt", "r") print(f.read())

`

**Output

Geeksforgeeks is best for DSA.

**Example 5: This example prints output to the error stream instead of the default output stream.

Python `

import sys company = "GFG" loc = "Noida" mail = "contact@gfg.org" print(company, loc, mail, file=sys.stderr)

`

**Output

GFG Noida contact@gfg.org

**Explanation: Using file=sys.stderr redirects the printed text to the error output stream instead of the standard output.