Basics

Module 2 · Basics · Lesson 8 of 9

Keyword arguments

Some arguments are passed by name instead of by position. These are keyword arguments, written as name=value. print has two especially handy ones: sep and end.

sep and end
print("a", "b", sep="-", end="!")
a·b
sep sits between values · endcomes after them (it's normally a new line)

sep (short for separator) sets what goes between your values — it defaults to a single space, but sep="-" joins them with dashes instead. end sets what comes after the last value — it defaults to a newline (that invisible \n), which is why each print normally starts a fresh line.

Change end and you can keep several prints on the same line. Because they have names, the order of keyword arguments doesn't matter — and they always come after your positional values. Try it:

Run it yourselfruns in your browser · Python
main.py