What is programming?

What a program is, how Python runs it one line at a time from top to bottom, and your first lines of code with print.

Lesson · 12 min

In this lesson you will

  • Explain what a program is in plain words
  • Run a Python cell and read its output
  • Use print to show text and numbers
  • Predict the order in which lines of a program run

Welcome! If you have never written a line of code, you are in exactly the right place. By the end of this lesson you will have written and run your first program, and you will know the one rule that explains almost everything a computer does with your code.

A program is a list of instructions

A program is a list of instructions written down so precisely that a computer can follow them. A recipe is a good comparison: “crack two eggs, whisk them, heat the pan”. The difference is that a computer has no common sense at all. It will never guess what you meant, and it will never skip a step that looks silly. It does exactly what you wrote, nothing more.

That sounds like a weakness, but it’s the computer’s superpower. Because it follows instructions exactly, it can follow millions of them a second without getting bored or tired.

Programming is the craft of writing those instructions. The language we write them in is called a programming language, and the one you’ll learn here is Python. Python is used by beginners and by the people who build modern AI, which is why this whole path is built on it.

Your first line of code

Below is a code cell. It holds one line of Python. Press Run and watch what appears underneath.

print("Hello, world!")

The words Hello, world! appeared below the cell. That area is the output: what the program shows you. The instruction print means “show this”. Whatever is inside the round brackets gets shown. The quote marks tell Python that Hello, world! is a piece of text, not an instruction.

Now change it. Click into the cell, replace the message with your own name, and run it again. You can’t break anything here: if a cell gets into a mess, just edit it back or reload the page.

Python reads from top to bottom

Here is the one rule. Python runs your program one line at a time, starting at the top and working down. It finishes each line before it starts the next.

Before you run the next cell, predict: in what order will the three messages appear?

print("First, put on your socks.")
print("Then put on your shoes.")
print("Now go outside.")

They came out in the same order as the lines. Try swapping two of the lines (cut one and paste it above the other) and run again. The output changes order too, because the program did.

The graphic below lets you slow this down. Press Step to run one line at a time. The line that just ran is highlighted, and the next line to run is outlined. Watch the output grow.

Loading the interactive graphic…

Here is a tiny program with four lines. Nothing has run yet, so the output is empty.

Text versus numbers

Did you notice line 3? print(2 + 3) showed 5, not 2 + 3. Without quote marks, Python treats what’s inside as something to work out. With quote marks, it treats it as text to show exactly as written. Predict what each line shows, then run it:

print("2 + 3")
print(2 + 3)
print(10 * 4)

The * symbol means multiply. You’ll meet all of Python’s arithmetic in a later lesson; for now, notice that the first line shows the characters 2 + 3 and the second shows the answer.

Several things in one print

You can give print more than one thing, separated by commas. It shows them in order with a space between each:

print("Minutes in a day:", 24 * 60)
print("My lucky numbers are", 7, "and", 21)

When something goes wrong

Here is a line with a mistake in it:

print("Where is my closing quote?)

If you ran it, you would not get any output. Instead Python would show an error message like this:

SyntaxError: unterminated string literal (detected at line 1)

Python is saying “I couldn’t understand this line”. The closing quote mark is missing, so Python can’t tell where the text ends. Copy that broken line into the cell below, run it to see the error for yourself, then add the missing " just before the bracket and run it again.

print("Paste the broken line over this one, then fix it.")

Errors are completely normal. Professional programmers see them all day long. An error is not the computer telling you off; it’s the computer telling you where to look. You’ll learn to read error messages properly later in this section.

Your turn

The exercise below checks your work automatically. Write the code, press Check, and read the feedback. If you get stuck, open a hint; each one gets you a little closer.

Exercise · Python

Your first program

Make a variable called message that holds the text Hello, Python! (exactly, with the comma and the exclamation mark), and print it.

Variables are coming properly in a couple of lessons. For now, think of message = "..." as “remember this text under the name message”, so the checker can look at it.

# Put the right text between the quotes, then print it
message = ""

Check yourself

Self-check · 4 questions

What is programming?

1. What is a program?
2. In what order does Python run the lines of a simple program?
3. What does print(4 + 4) show?
4. What does print("4 + 4") show?