Lesson 8
sep and end in print
After this lesson: You'll change what print puts between the values (sep) and what it prints at the end of the line (end).
Video
The video for this lesson is coming soon.
Explanation
You already know two things about print: a comma puts a space between values, and every print ends with a new line. Today you'll learn to change both habits! ๐ ๏ธ
sep - what goes between the values
Normally print(1, 2, 3) prints 1 2 3 - there's a space between the values. You can change that: at the end, after a comma, add sep="..." (short for separator).
print(1, 2, 3, sep="-")prints1-2-3,print(1, 2, 3, sep="")prints123- an empty separator glues the values together.
The separator goes only between the values - not at the start and not at the end.
Bajtek writes a date on an invitation ๐ฌ
Click Next to go step by step.
A birthday invitation
Bajtek is making birthday invitations. He wants to print the date the way it's written in a notebook: 16.10.2026 - with dots.
A dash instead of a space
First a normal print - there's a space between the names. Then the same print with sep="-" - a dash appears where the space was.
Click the arrow - you'll see what print puts between the values.
1print("Ala", "Ola")2print("Ala", "Ola", sep="-")
โThe same three, different separators
The values are the same - only what stands between them changes.
Click the arrow - you'll see what print puts between the values.
1print(1, 2, 3)2print(1, 2, 3, sep="-")3print(1, 2, 3, sep="")4print(1, 2, 3, sep=" and ")
โA separator only between
The same separator stands between every pair of values - but never at the end. And when there's only one value, there's nothing to separate: no dash at all.
Click the arrow - you'll see what print puts between the values.
1print("x", "y", "z", sep="+")2print("x", "y", "z", sep="*")3print("x", "y", "z", sep=" - ")4print("x", sep="-")
โWhat does the program print?
print("a", "b", "c", sep="+")
A date and a time ๐
The same kind of numbers, different separators: a dash for the date, a colon for the time.
Click the arrow - you'll see what print puts between the values.
1print(15, 10, 2026, sep="-")2print(15, 10, 2026, sep=".")3print(12, 45, sep=":")
โGlued without spaces
sep="" puts nothing in - the values stand right next to each other.
1print("Ala", "Ola", "Kuba")2print("Ala", "Ola", "Kuba", sep="")3print("Ala", "Ola", "Kuba", sep=", ")
โend - what goes at the end of the line
Normally every print moves to a new line at the end, which is why the next print writes below. With end="..." you say what goes at the end instead of the new line:
print("Ala", end=" ")- a space at the end, and the next print writes on in the same line,print("Ala", end="")- nothing at the end: the next print sticks on straight away.
Bajtek counts down to the rocket launch ๐ฌ
Click Next to go step by step.
A countdown on one line
Bajtek is building a rocket ๐ and wants the countdown on one line: 3 2 1 Start!
First two lines, then one
Lines 1-2: normal prints - each ends with an Enter โ, so there are two lines. Lines 3-4: the same text, but the first print has end=" " - it puts a space instead of the Enter and the second print writes on.
๐ฅ๏ธ Lines on the screen
โ
Click the arrow - you'll see what every print puts at its end.
1print("Ala")2print("has a cat")3print("Ala", end=" ")4print("has a cat")
โTwo prints, one line
Watch the screen: after the first print the cursor stays on the same line.
1print("Ala", end=" ")2print("has a cat")3print("[", end="")4print("###", end="")5print("]")
โThree different endings
Each time two prints: Ola and a question mark. Without end - two lines. With end=" " - one line with a space. With end="" - one line without a space.
1print("Ola")2print("?")3print("Ola", end=" ")4print("?")5print("Ola", end="")6print("?")
โWhat does the program print?
print("Bajtek", end="")print("!")
A train of wagons ๐
Every print adds one wagon, and end="-" puts a coupling after it. The last wagon has no end - it ends the line normally.
๐ฅ๏ธ Lines on the screen
โ
Click the arrow - you'll see what every print puts at its end.
1print("[LOK]", end="-")2print("[A]", end="-")3print("[B]", end="-")4print("[C]")
โA loading bar โณ
Every piece is added to the same line, because end="" doesn't go down.
1print("Start", end="")2print(".", end="")3print(".", end="")4print(".", end="")5print("OK")
โsep and end together
You can use both in one print: sep says what goes between the values, and end - what goes at the end.
The time and lunch ๐ฝ๏ธ
sep=":" glues the time together, and end=" " puts the word lunch on the same line.
1print(12, 30, sep=":", end=" ")2print("lunch")
โA date on an invitation ๐
sep="." puts dots between the numbers of the date, and end=" - " adds a dash with spaces at the end - the next print writes on in the same line.
1print(16, 10, 2026, sep=".", end=" - ")2print("Bajtek's birthday")
โThe guest list ๐ฌ
sep=", " puts a comma and a space between the names, and end=" " keeps the rest of the sentence on the same line.
1print("Ala", "Ola", "Kuba", sep=", ", end=" ")2print("go to the cinema")
โA cinema ticket ๐๏ธ
Four prints, but one line on the screen! Every print has its own end, so the next one writes on. Inside, sep glues the date with dots and the time with a colon. Only the last print, without end, ends the line.
1print("Ticket", end=": ")2print(16, 10, 2026, sep=".", end=", ")3print(18, 30, sep=":", end=", ")4print("row", 5, "seat", 12)
โCommon mistakes
sepandendgo at the end, after all the values:print(1, 2, sep="-").sep=""(empty) is not the same assep=" "(a space).- After
end=""the next print doesn't start a new line - if you want to go down, you need a plainprint().
Remember
sep="..."- what goes between the values (normally a space).end="..."- what goes at the end of the line (normally a new line).- With
end=""orend=" "the next print writes on in the same line.
Now you're the one setting up print! The tasks are waiting. ๐ ๏ธ
Tasks from the video
We solve them together in the video - pause it and try first on your own.
Practice tasks
Try to solve them without the video. Stuck? Every task has hints and an editorial.
Sign in to save your progress.