The dragon explains
Telling print HOW to speak
The dragon: You've been telling me WHAT to say. Now I'll show you how to change HOW I say it.
The dragon: First: print() can take more than one thing at once. Just put a comma between them.
example.pyPython 3print("Fire", "Ice")OutputFire IceThe dragon: Notice the space between them? I put that there myself. You never typed it.
example.pyPython 3print("Fire", "Ice")OutputFire IceThe dragon: That space is a setting called sep — short for separator. You can change it to anything.
example.pyPython 3print("Fire", "Ice", sep="-")OutputFire-IceThe dragon: Set it to nothing at all, and the words run straight together.
example.pyPython 3print("Fire", "Ice", sep="")OutputFireIceThe dragon: There's a second setting: end. It's what I say AFTER everything else — normally a new line.
example.pyPython 3print("Fire")print("Ice")
OutputFire IceThe dragon: Change end to "" and I don't start a new line at all. I just keep going.
example.pyPython 3print("Fire", end="")print("Ice")
OutputFireIce
Quick check
Check your understanding
Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.
Question 1 of 2
What will I say here?
question.pyPython 3print("day", "night", sep="/")- day/nightCorrect
- day night/
- day night sep="/"
Why: sep replaces the space I'd normally put between things, so the slash goes in the middle: day/night. It changes what's BETWEEN, never what's at the end.
Question 2 of 2
How many lines will I say here?
question.pyPython 3print("up", end="")print("down")
- One line: updownCorrect
- Two lines: up, then down
- One line: up down
Why: end="" replaces the new line with nothing at all, so the next print starts right where the last one stopped. One line, and the words run together: updown.
In the game
What you'll practice
Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.
- 1
GuidedYour first try
The dragon wants to say your name and your title together, in one breath — not as two separate lines. Hand print() two things at once.
- +2
PracticeTwo more, on your own
Try it yourself — in real Python.
This lesson is part of a free topic: every lesson in it is free, and no card is needed.
Start this lesson for realStuck three times? The game offers the answer — unasked.