Code of the Day

What is a program?

Computers are instruction-followers. Here you will write your very first Python instructions and see them run.

First Steps6 min read
By the end of this lesson you will be able to:
  • Describe what a program is and what a computer actually does with it
  • Run a Python print statement and read its output
  • Explain the difference between source code and execution

A computer is an extremely fast, extremely literal instruction-follower. Left to itself it does nothing — it waits. A program is the list of instructions you give it. Each line says exactly what to do, in what order. The computer carries those instructions out one by one, without judgment or improvisation.

That sounds constraining, but it is actually the whole point: because the machine does exactly what you write, you can reason about what will happen before you even run anything. Programming is the skill of writing instructions precisely enough that the machine does what you intended.

Source code, execution

The instructions you type in a text file are called source code. When you run the file, a program called the interpreter reads that source code and carries out each instruction in turn. Python is interpreted this way: you write a .py file (or type into a browser like this one), and Python reads and executes it line by line.

The gap between "what you wrote" and "what runs" is where bugs live. Understanding that gap — that the machine does exactly what the code says, which might not be what you meant — is the most important mindset shift in learning to program.

Why Python?

Python was designed to read almost like English. Its rules are consistent, its error messages are informative, and it runs everywhere. Almost everything you will learn here — variables, loops, functions, data structures — applies in every other language too. Python just gets the syntax out of the way so you can think about the concepts.

Your first instruction: print

The print function tells Python to display a value. It is the simplest way to see that your program is doing something.

Python — editable, runs in your browser

Click Run. You should see Hello, world! appear below. Now change the text inside the quotes and run it again. You just modified a program.

Python can also act as a calculator. Arithmetic expressions are evaluated and print shows the result:

Python — editable, runs in your browser

Each print call runs in order, top to bottom. The output appears one result per line. Try changing the numbers.

The text inside print("...") must be wrapped in quotes. The quotes tell Python "this is literal text, not an instruction." Numbers like 2 + 3 need no quotes — they are values Python can compute directly.

Check your understanding

Knowledge check

  1. 1.
    What is a program?
  2. 2.
    What does print("Hello") do?
  3. 3.
    Source code and execution are the same thing: typing a program runs it automatically.

Where to go next

Next: variables — giving names to values so your program can remember and reuse them.

Finished reading? Mark it complete to track your progress.

On this page