Python print() sep and end Arguments Explained

sep and end — the settings that change the shape of what I say.

  • Lesson 2 of 5
  • Free
  • Ages 10+
  • 3 hands-on levels
Try this lesson interactivelyReal Python, running in your browser.

The dragon explains

Telling print HOW to speak

  1. The dragon: You've been telling me WHAT to say. Now I'll show you how to change HOW I say it.

  2. The dragon: First: print() can take more than one thing at once. Just put a comma between them.

    example.pyPython 3
    print("Fire", "Ice")
    OutputFire Ice
  3. The dragon: Notice the space between them? I put that there myself. You never typed it.

    example.pyPython 3
    print("Fire", "Ice")
    OutputFire Ice
  4. The dragon: That space is a setting called sep — short for separator. You can change it to anything.

    example.pyPython 3
    print("Fire", "Ice", sep="-")
    OutputFire-Ice
  5. The dragon: Set it to nothing at all, and the words run straight together.

    example.pyPython 3
    print("Fire", "Ice", sep="")
    OutputFireIce
  6. The dragon: There's a second setting: end. It's what I say AFTER everything else — normally a new line.

    example.pyPython 3
    print("Fire")print("Ice")
    OutputFire Ice
  7. The dragon: Change end to "" and I don't start a new line at all. I just keep going.

    example.pyPython 3
    print("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.

  1. Question 1 of 2

    What will I say here?

    question.pyPython 3
    print("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.

  2. Question 2 of 2

    How many lines will I say here?

    question.pyPython 3
    print("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. 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. +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 real

Stuck three times? The game offers the answer — unasked.