print()
Writes text, numbers and any other values to the screen, with control over the separator, the line ending and where the output goes.
print(*objects, sep=' ', end='\n', file=None, flush=False)print() shows values on the screen. You can give it as many values as you like, separated by commas: it turns each one into text, puts a space between them and starts a new line at the end.
It is the first function almost everyone learns, and it stays useful forever: to show results, to build simple reports and to look inside a program while you are fixing it.
Two keyword arguments change the layout: sep is what goes between the values (a space by default) and end is what goes after the last one (a new line by default). Set end="" and the next print() continues on the same line.
Parameters
| Parameter | What it is |
|---|---|
*objectsoptional | Any number of values, of any type. Each one is turned into text the same way str() does it. With no values, print() writes an empty line. |
sepoptional, default ' ' | The text placed between the values. Must be given by name: sep=", ". |
endoptional, default '\n' | The text written after the last value. The default is a new line. |
fileoptional, default None | Where to write. None means the screen (standard output). Any open text file works too. |
flushoptional, default False | When True, the text is pushed out at once instead of waiting in a buffer. Useful for progress messages in long programs. |
Return value
Nothing (None). print() only writes; it does not give back the text.
Examples
1Print several values at once
item = "notebooks"
count = 3
print("You bought", count, item)
print()
print("Done")You bought 3 notebooks Done
The values are joined with spaces, and numbers are turned into text for you. print() with nothing inside writes an empty line.
2Change the separator and the line ending
print("2026", "03", "14", sep="-")
print("Loading", end="...")
print("done")2026-03-14 Loading...done
Because the second line ends with "..." instead of a new line, the third print() continues on the same line.
3Format prices with an f-string
An f-string (a string with f before the quote) lets you put values inside the text and choose how they look.
name = "Coffee"
price = 3.5
qty = 2
print(f"{name}: ${price:.2f} x {qty} = ${price * qty:.2f}")Coffee: $3.50 x 2 = $7.00
:.2f shows exactly two decimals, which is what you want for money.
4Print the items of a list without brackets
shopping = ["tea", "milk", "bread"]
print(shopping)
print(*shopping)
print(*shopping, sep=", ")
print(*shopping, sep="\n")['tea', 'milk', 'bread'] tea milk bread tea, milk, bread tea milk bread
The * unpacks the list, so print() receives three separate values instead of one list.
5Write to a file instead of the screen
with open("log.txt", "w") as f:
print("Backup started", file=f)
print("Backup finished", file=f)
with open("log.txt") as f:
print(f.read().strip())Backup started Backup finished
With file=f, nothing appears on the screen until we read the file back.
Common mistakes
Joining text and numbers with +
+ only joins text to text. Either pass the values to print() separated by commas, convert the number with str(), or use an f-string.
age = 30
try:
print("Age: " + age)
except TypeError:
print("TypeError: cannot add a str and an int")
print("Age:", age)
print("Age: " + str(age))
print(f"Age: {age}")TypeError: cannot add a str and an int Age: 30 Age: 30 Age: 30
Storing the result of print()
print() returns None, not the text it wrote. If you need the text, build the string first and then print it.
message = print("Hello")
print(message)
message = "Hello"
print(message.upper())Hello None HELLO
Writing print without brackets
In old Python 2 code you will see print "Hello". In Python 3 print is a function, so the brackets are required; without them you get a SyntaxError.
Questions people ask
How do I print without a new line in Python?
Pass end="": print("Loading", end=""). The next print() then continues on the same line.
How do I print a number with 2 decimal places?
Use an f-string: print(f"{total:.2f}"). This only changes how it looks; to change the number itself, see round().
How do I print several values without spaces between them?
Set sep="": print("a", "b", sep="") prints ab.
How do I print an error message to stderr?
Import sys and write print("Something went wrong", file=sys.stderr). Terminals show it like normal output, but it can be redirected separately.