Skip to content

Your first program: print()

4 min read

By the end of this lesson you'll have written programs that talk back: words, numbers, and a receipt with neat lines. You'll also meet your first error messages and learn to read them calmly. Everything in this lesson runs here in your browser, so a phone is enough.

Quotes change everything

Here are two lines that look almost the same. Before you read any explanation, guess what each one does.

What will this print?

Decide before you look. Guessing wrong is how this sticks.

print("Selam")
print(Selam)

Python prints

Selam
Traceback (most recent call last):
  File "<your code>", line 2, in <module>
    print(Selam)
          ^^^^^
NameError: name 'Selam' is not defined

The first line prints the text Selam. The second has no quotes, so Python doesn't treat Selam as text: it looks for something named Selam, finds nothing, and stops with a NameError.

Now run the first line on its own. Then click into the code, change the words, and run it again. You just edited a program.

print("Selam")

In the editor, press Escape then Tab to move on.

print is a : a tool with a name that does one job. Its job is to show values on the screen. You put what you want to show inside the parentheses.

The text between the quotes is a . Python doesn't try to understand a string. It shows it exactly as written, without the quotes. Without quotes, Python reads a word as a name, and looks for what that name means. Selam doesn't mean anything to Python yet; in Module 1 you'll learn to give names a meaning.

A diagram in three steps. First, your code: print with the string Selam. Second, Python reads the line. Third, the word Selam appears on the screen without quotes.
What happens when you press Run: Python reads each line and shows the result.

So a tiny difference, two quote marks, changes what Python does completely. Python never guesses what you meant. It does exactly what you wrote.

A program can have many lines. Python runs them from top to bottom, and each print starts a new line.

print("Good morning, Hana.")
print("Your macchiato is ready.")
print("That will be 45 birr.")

In the editor, press Escape then Tab to move on.

Words and numbers

Numbers don't need quotes. Without quotes, Python treats a number as a number, so it can do arithmetic before printing. With quotes, the same characters are only text.

What will this print?

Decide before you look. Guessing wrong is how this sticks.

print("2 + 3")
print(2 + 3)

Python prints

2 + 3
5

With quotes, 2 + 3 is text, so it's shown as typed. Without quotes, Python adds the numbers first and prints the result.

print(250)
print(250 + 30)
print(1200 - 350)

In the editor, press Escape then Tab to move on.

Printing several things

You can give print several values at once, separated by commas. This is how you mix text and numbers on one line.

What will this print?

Decide before you look. Guessing wrong is how this sticks.

print("Total:", 120, "birr")
Pick the output

Python prints

Total: 120 birr

The commas separate the values in your code; they are not printed. Between values, print adds one space.

That space is only the default. Two settings change how print joins things and how it finishes:

  • sep is what goes between values. It's a space unless you say otherwise.
  • end is what goes after the last value. It's a new line unless you say otherwise.
print("29", "09", "2026", sep="/")
print("Loading", end="...")
print("done")

In the editor, press Escape then Tab to move on.

The first line joins three values with / instead of spaces. The second ends with ... instead of a new line, so the next print carries on along the same line.

Now change it: make the first line print your name and city on one line, separated by - (a space, a dash, a space), like Hana - Addis Ababa.

Quick check

What does print(1, 2, 3, sep="") show?

New lines inside a string

Two more ways to control lines. Inside a string, \n means "start a new line here". And print() with nothing inside prints an empty line.

print("Selam Coffee\nBole Road")
print()
print("Open every day")

In the editor, press Escape then Tab to move on.

Reading error messages

Sooner or later, and usually sooner, Python will stop and show you an . This is normal. Programmers see errors all day. The trick is to read the last line first: it names the problem, and in Python 3.14 it often suggests the fix. Here are four you'll almost certainly meet.

Your turn. Run this, read the last line of the error, and fix it.

prnt("Selam")

In the editor, press Escape then Tab to move on.

Quick check

print(Hana) gives NameError: name 'Hana' is not defined. What's the fix?

Exercise

Print a taxi receipt

Write a program that prints a receipt for a taxi ride over three lines, exactly like this. Use print with several values for the fare line, so the number isn't inside the quotes.

Output
From: Bole
To: Piassa
Fare: 250 birr

Your code

# From, to, and fare, one line each

In the editor, press Escape then Tab to move on.

Show a solution

This is one way to solve it, not the only one. If yours prints the same thing, it works.

print("From: Bole")
print("To: Piassa")
print("Fare:", 250, "birr")

Key takeaways

  • print() shows values on the screen, one line per call.
  • Quotes make text. Without quotes, Python looks for a name, and a name it doesn't know is a NameError.
  • Commas give print several values; sep sets what goes between them and end what comes after. \n starts a new line inside a string.
  • Read the last line of an error first. It names the problem and often suggests the fix.