livepython.net
CHAPTER 02The Print Function
2.3  SEP AND END

print() sep and end Parameters Explained

Parameters: Extra Settings for a Function

You already know two things print() does on its own:

  1. It puts a space between the items you give it.
  2. It ends every line, so the next print() starts on a new line.

Most of the time that's what you want. But you can change both! You do it with parameters.

A parameter is a named setting you can give a function. You write its name, an = sign, and the value you want, inside the brackets, after your items:

PYTHONedit me
print("apple", "banana", sep=" | ")
OUTPUT
apple | banana

Here sep is the parameter, and " | " is the value you chose for it. The value you pass is called an argument.

Think of ordering a cup of tea: "tea, please" gets you the normal one. "Tea, with no sugar" changes one setting. The tea is your text, and "no sugar" is a parameter.

print() has two parameters you'll use all the time:

ParameterControlsNormal value
sepwhat goes between the itemsone space
endwhat comes after the last itema new line

If you don't set them, print() uses the normal values. That's why everything you printed so far had spaces between items and ended with a new line.

Parameters are named settings: name=value, after your items.

your turnPick the right idea

In print("a", "b", sep="-"), what is sep?

Think about it, then pick one.

Change the Separator with sep

sep is short for separator: what goes between the items. Normally it's a space. Change it, and the output changes:

PYTHONedit me
print("02", "11", "2026", sep="-")
print("02", "11", "2026", sep="/")
OUTPUT
02-11-2026
02/11/2026

Same items, different separators: you made two date formats.

Some useful separators

PYTHONedit me
print("Sunny", "Rocky", "Lucky", sep=", ")
print("Live", "Python", sep="")
print("one", "two", sep="\n")
OUTPUT
Sunny, Rocky, Lucky
LivePython
one
two
  • sep=", " makes a list with commas.
  • sep="" (empty quotes) glues the items together with nothing between them.
  • sep="\n" puts each item on its own line.

sep is only used between items

If you print a single item, sep has nothing to separate, so it does nothing:

PYTHONedit me
print("Hello", sep="***")
OUTPUT
Hello

Common beginner doubt: "Why does sep="," give a,b but sep=", " gives a, b?" Because the space is part of the separator. sep puts exactly what's inside its quotes, nothing more.

sep decides what goes between the items: anything you put in its quotes.

your turnPredict the output

What will this print?

print("a", "b", "c", sep="")
Your turn! What will this code show on the screen?
your turnFill the gap

Make it print 2026/11/02

print("2026", "11", "02", sep=?)

It should print: 2026/11/02

Which piece makes this code work?

Change the Line Ending with end

end decides what print() adds after the last item. Normally it's \n, a new line. That's why each print() starts on a new line.

Change end, and the next print() continues on the same line:

PYTHONedit me
print("Hello", end=" ")
print("World")
OUTPUT
Hello World

The first print() ended with a space instead of a new line, so World came right after it.

Some useful endings

PYTHONedit me
print("Loading", end="")
print("...", end="")
print(" done!")
OUTPUT
Loading... done!
  • end=" " ends with a space, so the next print continues after it.
  • end="" ends with nothing at all.
  • end="!\n" ends with an exclamation mark, then a new line.

Don't forget the last line

If the last print() also has end="", nothing ends the line. Usually that's fine on LivePython. But it's a good habit to let your final print() use the normal ending, so whatever comes next starts on a fresh line.

Think of end as the punctuation at the end of a sentence. Normally it's "go to the next line". You can change it to a space, a comma, or anything you like.

end decides what comes after the last item. Normally it's a new line.

your turnType the output

Type what this prints

print("Good", end=" ") print("night")
Read the code line by line, then type the output exactly.
your turnOrder the lines

Put the lines in order to print: Ready set go!

  1. print("set", end=" ")
  2. print("go!")
  3. print("Ready", end=" ")
These lines are mixed up. Put them back in order, then press Check.

Using sep and end Together

You can use sep and end in the same print(). Put them after your items, separated by a comma:

PYTHONedit me
print("A", "B", "C", sep="-", end="!\n")
OUTPUT
A-B-C!

sep="-" goes between the letters, and end="!\n" adds an exclamation mark, then a new line.

The order of sep and end doesn't matter

These two lines do exactly the same thing:

PYTHONedit me
print("1", "2", "3", sep=", ", end=".\n")
print("1", "2", "3", end=".\n", sep=", ")
OUTPUT
1, 2, 3.
1, 2, 3.

Because each one has a name, Python knows which is which. Just remember: the items you want to print come first, and the named settings come after them.

A small example: a shopping list in one line

PYTHONedit me
print("Shopping:", end=" ")
print("milk", "bread", "eggs", sep=", ", end=".\n")
OUTPUT
Shopping: milk, bread, eggs.

Two print() lines, one line of output. The first ends with a space. The second joins the items with commas and ends with a full stop.

Common beginner doubt: "Can I print sep= itself?" Only inside quotes: print("sep=") prints the text sep=. Without quotes, Python treats it as the parameter.

Items first, settings after: sep goes between, end goes last.

your turnFix the code

Make it print: A-B-C!

It should print: A-B-C!

print("A", "B", "C")
This code does not work yet. Fix it, then press Run.

Practice: sep and end

Solve these to lock in what you learned in this topic. Each one runs in your browser.

  1. 8.Python Program to Print Details Separated by CommasEasySolve
  2. 9.Python Program to Print One Line with Several print() CallsEasySolve
  3. 15.Python Program to Print a List with sep and endMediumSolve