Python print() Function: Syntax and 5 Examples

The Python print function writes values to the screen. Pass it one or more objects, and print() turns each into a string, puts a space between them and ends the line.

print("Order", 1041, "shipped")
# Order 1041 shipped

You’ll rarely need more, but four keyword arguments let you change the separator, the line ending and where the text goes.

In this tutorial, I’ll show you the syntax, then five examples: mixed values, sep, same-line output, USD invoices and printing to a file. I ran them in Python 3.12.5 in VS Code.

Python print() Syntax

print(*objects, sep=' ', end='\n', file=None, flush=False)
ParameterRequiredDefaultDescription
*objectsNononeAny number of values; each is converted with str()
sepNo' 'String placed between the objects
endNo'\n'String written after the last object
fileNoNone (sys.stdout)Any object with a write(str) method
flushNoFalseTrue pushes the output out right away

Return value: print() always returns None. Its job is the side effect of writing text, not giving you a value back.

Note: the last four are keyword-only, and flush needs Python 3.3+. The star in *objects works like *args in Python functions.

When to Use print() in Python

  • Showing results in a quick Python script or a Jupyter notebook
  • Checking a variable’s value while debugging
  • Building simple command-line reports and progress messages
  • Writing short text lines to a log file or to sys.stderr

Mixing text with values? My post on printing a variable in Python compares commas and f-strings.

Example 1: Print Text, Numbers and Variables

Let me start with a sales summary for an Austin store. One call can take strings, integers, floats and even lists:

city = "Austin"
orders = 42
revenue = 3815.5

print("Daily sales report")
print("City:", city, "| Orders:", orders, "| Revenue:", revenue)
print()
print(True, None, [1041, 1042])

Output:

Daily sales report
City: Austin | Orders: 42 | Revenue: 3815.5

True None [1041, 1042]
Python print function showing text, numbers, a blank line and a list in VS Code
One space between each value, and the empty print() added a blank line.

How does this work? print() converted the numbers, True and the list to strings for you. With no arguments, it wrote just the line ending.

To glue numbers into one string instead, see printing strings and integers together.

Example 2: Change the Separator with sep

The space between values comes from sep. Change it to build dates, CSV rows or one item per line:

print("2026", "11", "23", sep="-")
print("ORD-1041", "Denver", "249.99", sep=",")

cities = ["Austin", "Denver", "Seattle"]
print(*cities, sep=" | ")
print(*cities, sep="\n")

Output:

2026-11-23
ORD-1041,Denver,249.99
Austin | Denver | Seattle
Austin
Denver
Seattle
Python print sep parameter joining values with a dash, a comma, a pipe and a newline
Four separators: a dash, a comma, a pipe and a newline.

How does this work? sep goes only between objects, never after the last one. The star in *cities unpacks the list, so print() sees three separate strings.

That unpacking trick is also the quickest way to print a list without brackets.

Example 3: How Do You Print on the Same Line in Python?

Every call ends with a newline unless you change end. Here’s a small progress indicator:

import time

print("Uploading invoices", end="")
for _ in range(3):
    time.sleep(0.3)
    print(".", end="", flush=True)
print(" done")

for step in ["Load", "Clean", "Save"]:
    print(step, end=" -> ")
print("Finished")

Output:

Uploading invoices... done
Load -> Clean -> Save -> Finished
Python print end parameter keeping a progress line and step names on the same line
The dots and the steps stayed on one line each.

How does this work? end="" skips the line break, so the next print() continues the same line. flush=True shows each dot right away instead of waiting for the buffer.

Pro Tip: printing on the same line covers carriage returns too, for counters that overwrite themselves.

Example 4: Format Prices with f-strings in print()

print() doesn’t format numbers itself, so pair it with an f-string. Here are three invoices lined up in columns:

invoices = [("INV-2041", "Emily Carter", 1249.5),
            ("INV-2042", "James Miller", 89.99),
            ("INV-2043", "Olivia Brooks", 23410.0)]

print(f"{'Invoice':<10}{'Customer':<15}{'Amount':>12}")
for inv, name, amount in invoices:
    price = f"${amount:,.2f}"
    print(f"{inv:<10}{name:<15}{price:>12}")

total = f"${sum(a for *_, a in invoices):,.2f}"
print(f"{'Total':<25}{total:>12}")

Output:

Invoice   Customer             Amount
INV-2041  Emily Carter      $1,249.50
INV-2042  James Miller         $89.99
INV-2043  Olivia Brooks    $23,410.00
Total                      $24,749.49

How does this work? :,.2f turned 23410.0 into 23,410.00. Then :<10 left-aligns the text and :>12 right-aligns each price.

For more format codes, see decimal places with Python f-strings.

Example 5: Print to a File or sys.stderr in Python

file= sends the text anywhere that has a write() method, like an open log file or the error stream:

import sys

with open("orders_log.txt", "w", encoding="utf-8") as log:
    print("2026-11-23 09:15 ORD-1041 shipped", file=log)
    print("2026-11-23 09:42 ORD-1042 shipped", file=log)

print("Missing ZIP code for ORD-1043", file=sys.stderr)

with open("orders_log.txt", encoding="utf-8") as log:
    print(log.read(), end="")

Output:

Missing ZIP code for ORD-1043
2026-11-23 09:15 ORD-1041 shipped
2026-11-23 09:42 ORD-1042 shipped
Python print writing order lines to a text file and an error message to sys.stderr
The stderr warning printed first, then the two lines read back from the file.

How does this work? the shipped lines went into orders_log.txt, not the screen. The warning went to sys.stderr, which a > out.txt redirect doesn’t capture.

Learn more about the three streams in Python stdin, stdout and stderr.

Common Mistakes with Python print()

You’ll hit these four sooner or later. I caught each one so the script keeps going:

total = 249.99

try:
    print("Total: " + total)
except TypeError as err:
    print("1. TypeError:", err)

try:
    print("ORD-1041", "Denver", sep=5)
except TypeError as err:
    print("2. TypeError:", err)

try:
    exec('print "Total:", total')
except SyntaxError as err:
    print("3. SyntaxError:", err.msg)

result = print("4. Saved")
print("   print() returned:", result)

Output:

1. TypeError: can only concatenate str (not "float") to str
2. TypeError: sep must be None or a string, not int
3. SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
4. Saved
   print() returned: None
Common Python print errors: TypeError for str plus float, TypeError for sep, and the Python 2 SyntaxError
Two TypeErrors, the Python 2 SyntaxError and a None return value.
  1. String + float fails before print() runs. Use a comma or an f-string.
  2. sep and end take strings only.
  3. print "text" is Python 2 syntax; Python 3 needs parentheses.
  4. print() returns None, so don’t store its result.

The first error has its own fix-it post: concatenating a string and a float.

Wrapping Up the Python print() Function

Python’s print() function looks simple, but sep, end, file and flush cover separators, same-line output, log files and live progress.

Pair it with f-strings, and when you’re ready, browse more Python built-in functions and methods.

Next, try these related print tutorials:

Python print() Function: Common Questions

What is the difference between print() and return in Python?

print() shows a value. return hands it back to the caller so your code can use it.

Is print a function or a statement in Python?

In Python 3 it’s a built-in function. Python 2 used a print statement without parentheses.

Why doesn’t my print() output show up right away?

The output is buffered. Pass flush=True, or run the script with python -u.

Should I use print() or logging?

print() is fine for quick scripts. In apps, the logging module adds levels and timestamps.

Can print() write to a binary file?

No. It writes strings, so a file opened with "wb" raises TypeError. See print() in the Python docs.