BeginnerLesson firstCategory 2 of 20

Standard Output (Printing)

Learn how to display information to the screen using print(). Read the lesson first, then move through the exercises in order.

12 Sections5 Exercises

After reading

Practice Arena

Begin with the first exercise, then continue step by step through the module.

Start with Hello World

Study Material

Read the full lesson

The Power of print()

Imagine you are sitting in a massive, silent room where a supercomputer is processing millions of calculations every second. The room has no screens and no speakers. How do you know what the computer is doing? You need a way for it to talk to you.

In programming, this is called standard output. It is one of the first ideas every beginner needs to learn.

In Python, the tool we use to make the computer talk is the print() function. Think of print as a command that means "show this on the screen."

Every time you use this command, you follow it with parentheses (). Whatever you put inside the parentheses gets displayed.

python
print("Hello, World!")

If you want to print normal text, put that text inside quotes. You can use single quotes or double quotes.

python
print("Python") print('Python')

Both lines work. They produce the same result.

Printing text, numbers, and values

print() is not only for text. It can also show numbers and values stored in variables.

python
print("Age") print(25) name = "Maya" print(name)

The important rule is simple:

  • Text needs quotes.
  • Numbers do not need quotes.
  • Variable names do not need quotes.

If you forget the quotes around text, Python will think that text is a variable name. That usually causes an error.

Printing more than one thing at once

You can give print() more than one value by separating the values with commas.

python
print("Python", "is", "fun")

Python prints all the values on one line. By default, it places a space between them.

Output:

Python is fun

This is why print() feels easy to use. Python helps make the output readable.

The sep parameter

The space that Python adds between values is called the separator. If you want a different separator, use the sep parameter.

python
print("Python", "is", "fun", sep="-") print("2026", "03", "07", sep="/") print("A", "B", "C", sep="")

Output:

Python-is-fun
2026/03/07
ABC

Use sep when you want to control what appears between values.

This directly connects to your custom separator exercise.

Printing on more than one line

By default, print() finishes by moving to the next line. That is why separate print() calls usually appear one under another.

python
print("Line 1") print("Line 2") print("Line 3")

You can use this behavior to build shapes and simple ASCII art.

python
print(" /\_/\") print("( o.o )") print(" > ^ <")

That is the easiest way to solve the ASCII art exercise.

The newline character \n

There is another way to print multiple lines. Inside a string, \n means "start a new line here."

python
print("Line 1\nLine 2\nLine 3")

Output:

Line 1
Line 2
Line 3

This is useful when you want one print() call to produce more than one line.

Printing backslashes correctly

The backslash character \ is special in Python strings because it starts escape sequences like \n.

If you want to print a real backslash, you need to escape it by writing it twice.

python
print("\\")

Output:

\

This matters in the ASCII art exercise because the cat face uses backslashes.

Standard output and standard error

Normally, print() sends text to standard output, often written as stdout. This is the normal output channel for a program.

Python also has another channel called standard error, written as stderr. This channel is used for error messages.

To print to stderr, import the built-in sys module and pass file=sys.stderr.

python
import sys print("Program started") print("Error occurred", file=sys.stderr)

Both messages may appear on the screen, but they are being sent through different channels behind the scenes.

This is exactly the idea behind your stderr exercise.

The end parameter

By default, print() ends with a newline. That is why the next output starts on the next line.

If you want to change what print() adds at the end, use the end parameter.

python
print("Hello", end=" ") print("World")

Output:

Hello World

Here, the first print() ends with a space instead of a newline.

Use end when you want to control what appears after the full print is finished.

Using end inside a loop

The end parameter becomes very useful inside loops.

python
for i in range(1, 6): print(i, end=" ")

Output:

1 2 3 4 5

Without end=" ", each number would appear on its own line.

This directly connects to your final exercise in this module.

Common mistakes to avoid

These are the most common beginner mistakes on this topic:

  • forgetting quotes around text
  • forgetting that backslashes need escaping
  • mixing up sep and end
  • expecting print() to stay on one line without changing end

A simple rule helps:

  • Use sep for what goes between values.
  • Use end for what goes after the whole print finishes.

What you should understand after this lesson

After reading this page, you should be able to:

  • print a simple message
  • print several values together
  • change the separator between values
  • print multiple lines
  • handle backslashes in strings
  • send a message to stderr
  • keep output on one line with end

That is the full path of this module. Read the lesson, use the quick jump when needed, then move through the exercises in order.

Interactive

Exercises for this topic

These exercises follow the exact order of the lesson. Move step-by-step from reading into coding.