Basics · lesson 1 of 10
Parts in this lesson
Aprintshows something on the screen
B( )what to show goes inside
C"text"words in quotes

Your first program

Last updated

Your first Python program prints one line of text. You'll run it, change what it says, then break it on purpose and read what Python tells you.

By the end of this lesson you can

  • Say what a program is, and in what order Python runs its lines
  • Run a program and change what it prints
  • Read a SyntaxError and find the line it points at

What a program is

A program is a list of instructions, a lot like a recipe. A recipe says boil the water, add the pasta, wait ten minutes, and you do the steps in that order. The computer works through a program the same way, one instruction at a time, from the top down.

The difference is that a cook fills in gaps. If a recipe forgets to say "drain the pasta", you'd do it anyway. The computer never guesses what you meant: it does exactly what the lines say, in the order they say it, and nothing else. That's why a program has to spell out every step.

This program has three instructions, one on each line. Press Watch it run, then Next to go one line at a time. The pink line is the one that just ran, and the box underneath shows what has been printed so far.

Step 1 code main.py
Edit the code, then run it again

Where it starts: the top

A Python program starts at its first line and works down. There's nothing to mark the start: the first instruction in the file is the first one that runs. (Some languages, like Rust, start at a special place called main. Python doesn't need one.)

Look back at the program in step 1. Which line runs last?
print("Find a book on the shelf.")
print("Take it to the desk.")
print("Enjoy reading!")

Run it

print shows something on the screen. The round brackets hold what it should show. The text itself goes between double quotes, so Python knows where the text starts and stops.

Programmers have started with this one for about fifty years. Press Run.

Step 3 code main.py
Edit the code, then run it again

Change the text

Change Hello, world! to something else, like your name, and run it again. Only change what's between the quotes.

Then add a second line: copy line 1, paste it underneath, change its text, and run it. Each print prints its own line, in the order they're written.

Step 4 code main.py
Edit the code, then run it again

Read your first error

Now break it on purpose. In the code below, delete the " just after world!, then press Run.

Python reads the whole program before it runs any of it, and it can't read this one, so instead of output you'll get an error. The first lines are what Python really prints: the file, the line number, the line itself, and a ^ under the place where it got stuck. The last line names the problem. Under it is the same message in plain words.

Step 5 code main.py
Edit the code, then run it again

Put the quote back and run it again to make sure it works. Reading errors is most of programming, so every lesson in this course has a step like this one. A good habit starts here: read an error from the bottom up. The last line says what went wrong; the lines above it say where.

Check what you learned

Three questions. Pick or type an answer, then check it.

Where does a Python program start?
Which of these prints Hi?
This program won't run. Which line has the mistake?
print("Find a book.")
print("Take it to the desk)
print("Enjoy reading!")

Sources

Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.

All sources for Simple Python