runtime
02 / 250
lesson 02 Python Setup & First Programs · beginner

Printing and formatting

Print several values on one line, and choose what goes between them and after them.

You'll be able to
  • Print a label and a value with one print
  • Change what goes between values with sep=
  • Change the line ending with end=, and use \n for a new line
The idea

print can take several values, separated by commas. It prints them on one line with a single space between each. A label and a number are just two values.

Run each example to see what it prints. Running examples doesn't count toward progress.

example-1.py · A label and a value
print("Order", "O100043", "is", "delivered")
print("Items:", 1, "Total:", 12.93)

Two settings change that spacing. sep= is what goes between the values. end= is what goes after the last value. Normally that is a new line, so the next print starts on the next line. end="" puts nothing after the value, so the next print continues on the same line.

Inside quotes, \n means new line. You type two characters, a backslash and an n, and Python starts a new line there. It works with sep and with end.

example-2.py · Separators and line endings
print("2025", "11", "28", sep="-")
print("Status", end=": ")
print("delivered")
print("toys", "electronics", sep="\n")

When to use them: sep= when several values belong on one line with something other than a space between them (a date, a route, a table row); end= when the next print should continue the same line.

Mistakes to avoid: sep and end are easy to swap: end="-" puts one dash after the last value and leaves spaces between the values. The settings go inside the brackets, after the values. And /n with a forward slash is just two characters; a new line is a backslash: \n.

Review
  • Several values in one print are joined by spaces. The comma is not printed.
  • sep= sets what goes between values. end= sets what goes after the last value.
  • \n inside quotes is a new line.
Practise this

Loading your progress…

To master this lesson, solve both challenges without hints or the answer, and pass the concept check.

Printing and formatting — Python Setup & First Programs · Runtime