Lesson 1
Installing Python 3 and running your first program
What you'll learn: how to install Python 3, check that it works, and run your first program from a file.
Meet Nadia and her expense tracker
Nadia has a feeling that her money disappears faster than it should, but her banking app only shows a long scroll of transactions. She wants something simpler: a small program where she types in what she bought and how much it cost, and it tells her where the money went. Over the next twelve lessons she is going to build exactly that, one piece at a time, in Python.
Python is a programming language: a precise way of writing instructions that a computer can follow. It reads almost like English, which makes it a favourite first language, and professionals use it for everything from websites to data analysis. Everything in this course works on Windows, macOS and Linux.
Installing Python 3
You need Python 3. The old Python 2 stopped receiving updates in 2020, and nothing in this course will run on it. Any recent version of Python 3 is fine; new versions arrive every October, and the basics you will learn here have not changed in years.
How you install it depends on your computer:
| Your computer | How to install | Command to check it works |
|---|---|---|
| Windows | The installer from the official Python website, or Python from the Microsoft Store | py --version or python --version |
| macOS | The installer from the official Python website (Homebrew also works if you already use it) | python3 --version |
| Linux | Usually already installed; if not, your distribution's package manager | python3 --version |
On Windows, if the installer shows a box labelled "Add python.exe to PATH", tick it. It lets your terminal find Python. On macOS, typing python3 before installing anything may pop up an offer to install Apple's developer tools; the official installer is the simpler route for a beginner.
To check, open a terminal. On Windows that is Terminal or Command Prompt from the Start menu; on macOS it is Terminal in Applications, then Utilities. Type the check command from the table and press Enter. You should see something like this:
Python 3.13.2
The exact numbers will differ. Anything starting with 3 means you are ready. If you see "command not found" or "is not recognized", the installation did not finish or the PATH box was not ticked; running the installer again usually fixes it.
Two ways to run Python
Python can run your instructions in two ways, and it helps to know both from the start.
The first is the interactive prompt. Type python3 on macOS or Linux, or py on Windows, and press Enter. You will see three arrows:
>>>
This is Python waiting for an instruction. Type 2 + 3 and press Enter, and it answers 5 straight away. Type print("Hello, Nadia") and it shows Hello, Nadia. When you are done, type exit() and press Enter.
The second way is a program file: a plain text file, ending in .py, that holds a list of instructions. Python reads the file from top to bottom and carries out each line in order.
The difference between these two is the idea that trips up most beginners, so here is an everyday comparison. The interactive prompt is like a pocket calculator: you press keys, get an answer, and when you switch it off, nothing is kept. A program file is like a recipe card: you write the steps down once, and anyone can follow the same card tomorrow and get the same result. Nadia's tracker needs to be a recipe card, because she wants to run it again every day.
Writing the first line of the tracker
You need somewhere to write the file. Python comes with a simple editor called IDLE on Windows and macOS (on Linux it may be a separate package). A free code editor such as Visual Studio Code also works well. What matters is that the file is saved as plain text with a name ending in .py. A word processor will not do, because it adds hidden formatting.
Make a folder called tracker somewhere easy to find, such as your Documents folder. Inside it, create a file called tracker.py and type this single line:
print("Nadia's expense tracker")
Save the file. Now, in the terminal, move into the folder with the cd command (short for "change directory"). If the folder is inside Documents, that is:
cd Documents/tracker
Then run the program:
python3 tracker.py
On Windows, use py tracker.py instead. Python reads the file and prints:
Nadia's expense tracker
That is a complete program. It is small, but every program you will ever write is run in exactly this way.
What that line actually says
print is a function: a named action that Python already knows how to do. The round brackets hold what you are giving it, and the text inside the quotation marks is the message. The quotes tell Python "this is text, not an instruction". Leave one out and Python stops with an error, which is normal; lesson 10 is about reading those errors calmly.
Try adding two more lines to the file, each on its own line with no spaces in front:
print("Track what you spend, one item at a time.")print("Version 1")
Run it again and you will see three lines of output, in the same order as the file. Python always works from the top of the file down, one line after another, unless you tell it otherwise.
A note on how code appears in this course: each line of code is shown on its own, and when a program has several lines, each one is its own list item. Python cares about the spaces at the start of a line, so whenever a line needs to be indented, the lesson will say so in words.
Recap
- Install Python 3 for your system and check it with
python3 --version(orpy --versionon Windows). - The interactive prompt (
>>>) is a calculator for quick experiments; a.pyfile is a recipe card you can run again. - Write programs in a plain text editor such as IDLE or VS Code, never a word processor.
- Run a file with
python3 tracker.py(orpy tracker.py) from the folder that holds it. - Python runs a file from top to bottom, one line at a time.