Fundamentals · Lesson 2 of 94

Prerequisites, setup, and your first program

Watch this lesson

View full playlist ↗

Read the lesson

What you'll learn

Concept

You need three things to start: a computer you can install software on, the ability to open a folder and create a file, and patience for error messages. That is the whole list. No math beyond arithmetic, no previous programming.

Prerequisites, setup, and your first program: A computer → A folder and a file → Patience with errors → Ready
Prerequisites, setup, and your first program · Figure 1 · Open for full size

Python itself is a program. When you "run Python" you start that program and hand it your code, either one line at a time or as a whole file. Both ways are useful, and you will use both in every lesson.

Prerequisites, setup, and your first program: You → REPL: one line at a time → File: hello.py, top to bottom
Prerequisites, setup, and your first program · Figure 2 · Open for full size

The interactive mode is called the REPL, short for read, evaluate, print, loop. You type an expression after the >>> prompt, Python evaluates it and prints the result, then waits for the next one. It is the fastest way to try an idea. Since Python 3.13 the REPL has color and multi-line editing, and Python 3.14 added syntax highlighting as you type, so it is pleasant to live in.

Running a file is how real programs work. You save your code in a file ending in .py, then ask Python to run that file from top to bottom. Everything in this course is written as files, because files can be saved, shared, tested, and shipped.

Here is what happens when you install Python and run a file for the first time.

Prerequisites, setup, and your first program: Download installer → Install Python 3.14 → Install VS Code → Create hello.py → Run it in the terminal → See the output
Prerequisites, setup, and your first program · Figure 3 · Open for full size

Install steps differ a little by operating system, so here is the short version for each.

System Install Python Open a terminal
Windows python.org installer, tick "Add python.exe to PATH" Windows Terminal or PowerShell
macOS python.org installer, or brew install python@3.14 Terminal app
Linux Your package manager, or uv python install 3.14 Any terminal

You will run Python from a terminal, so you need four commands and no more. pwd prints the folder you are in, ls lists what is in it (dir on Windows PowerShell also works), cd name moves into a folder and cd .. moves back up, and python3 file.py runs a program. Everything else the terminal can do, you can learn later.

Command What it does
pwd show the folder you are in
ls list the files in this folder
cd course move into the folder called course
python3 hello.py run a program with Python

Following along works the same way in every lesson. Each code block names its file on the first line, like # hello.py. Create a file with that name in your course folder, type the code exactly, save, and run it with python3 hello.py. The output block right under the code is what the lesson got when it ran the same file. If yours matches, move on; if it does not, the difference is the lesson.

For the editor, install Visual Studio Code and its official Python extension. It is free, it runs everywhere, and it is what most Python developers use. When VS Code asks you to Select Interpreter, pick the 3.14 you just installed.

Code

First, confirm Python is installed and is the version this course uses. Open a terminal, type the command, and compare the output. On some systems the command is python instead of python3; whichever prints a version starting with 3.14 is the one to use.

# check_version.sh
python3 --version
Output
Python 3.14.7

Now the program every programmer writes first. Create a folder for this course, create a file inside it called hello.py, and type this one line. Save it.

# hello.py
print("Hello, world!")
Output
Hello, world!

In the terminal, move into your folder with cd and run the file with python3 hello.py. That output block is what you should see. If you do, you have a working Python setup and you have run your first program.

The REPL works differently: you type expressions and get answers immediately without a file. Start it by typing python3 on its own, and leave it by typing exit(). This script does in a file what you would type there interactively, so the output is identical either way.

# repl_demo.py
print(2 + 3)
print("py" * 3)
print(len("hello"))
Output
5
pypypy
5

Try it yourself

Change hello.py so it prints your own name on a second line, run it again, and confirm both lines appear. Then start the REPL, type 7 * 6, press Enter, and type exit() to leave. That is the whole loop you will repeat thousands of times: edit, run, read.

Common mistakes

What's next

Your tools work and you have run a program. Next you will learn the few layout rules every Python file follows, including the indentation that trips up almost every newcomer once.

Course overview