More ways to print

Getting Started, lesson 2 of 5

👋 Getting Started, lesson 2 of 5

More ways to print

Print several values at once and control spacing and line endings.

8 min

1 exercise

2 quizzes

0/3 solved

Getting Python ready… examples can run in a moment.

You can give print() several values separated by commas. Python prints them on one line with a space between each one. You can mix text and numbers freely.

Example

Several values

Notice the spaces Python adds between values. Add another value to the first line.

Two optional settings change how print() behaves:

  • sep="..." sets what goes between values (a space by default).
  • end="..." sets what goes after the last value (a new line by default).
Example

sep and end

Try sep="" or sep=" | ". What does end="" do?

Quiz

What does this print?

Inside a string, a backslash starts a special character called an escape sequence:

  • \n starts a new line
  • \t inserts a tab
  • \" puts a double quote inside a string

Calling print() with nothing inside prints an empty line.

Example

Escape sequences

Strings can use "double" or 'single' quotes, as long as both ends match.

Quiz

What does this print?

Exercise

Format a date

Change the print call so it prints the date with slashes, exactly like this:

30/09/2026

Keep the three separate values and use sep.