Command Palette

Search for a command to run...

Hectal
PHASE 0Beginner ~26 min· topic 4 of 8

Topic 0.4

Run Your First Program: Here, Then on Your Computer

In one line

You can run Python on this page with the Run button and nothing installed. To work on your own computer, install Python from python.org, save your code in a file ending in .py, and run it from a terminal with python hello.py (python3 on macOS and Linux).

Think of it like this

Learning to drive. You start in a simulator, where nothing can go wrong and you can retry in a second. Then you move to a real car, because that is where real journeys happen. The Run button on this page is the simulator. Python on your own computer is the real car.

Words you'll meet

New words in this topic, in plain English. Come back here whenever one feels fuzzy.

Interpreter
The program (named python) that reads Python code and carries it out, line by line.
Terminal
A window where you type commands and read their text output. Also called a command line or shell.
Command
A line you type in a terminal to run a program, such as python hello.py.
Folder (directory)
A place on disk that holds files. A terminal always has a current folder.
cd
The terminal command to change the current folder, for example cd python-course.
File extension
The ending of a file name after the dot. Python files end in .py.
Code editor
A program for writing code as plain text, with colouring and helpers. VS Code is one.
PATH
A system setting listing the folders where the terminal looks for commands. Python's folder must be on it for python to work.
Script
A Python file that you run directly, top to bottom.

Step by step

01Start here: the Run button

Scroll to the first example below and press Run. The first run of a visit takes a few seconds, because your browser downloads Python itself; after that, runs are instant. Change the text inside the quotes and run again.

The Run button needs you to be signed in, and it cannot read the keyboard, so examples use fixed values in place of typed input. Everything else is the real language.

main.pywhole filepython
print("Hello, World!")

02Install Python on Windows

Go to python.org/downloads and download the installer for the current version. On the installer's first screen, tick "Add python.exe to PATH" before you click Install. That tick is what lets the terminal find the python command. (Newer python.org downloads for Windows may offer the Python install manager instead. It also provides the python and py commands; follow the steps on its page, and check with python --version afterwards.)

Then open a new PowerShell window (old windows don't see the new PATH) and check the version. If Windows opens the Microsoft Store when you type python, Python isn't on your PATH yet: run the installer again and tick the PATH box, or use py instead of python.

terminal
$ python --version
── expected output ──
Python 3.14.0
py --version works too. py is a launcher that Windows installs alongside Python.

03Install Python on macOS and Linux

macOS: download the macOS installer from python.org and run it. Or, if you use Homebrew (a tool that installs programs from the terminal), run brew install python. The command you type afterwards is python3.

Linux: Python 3 is almost always already installed, because the system itself uses it. Check with python3 --version. On Ubuntu or Debian, sudo apt install python3 installs it if it is missing (sudo means "run this as administrator"). The system's Python may be a version or two behind the newest. That is fine for this course, and Topic 6.6 shows how to install any version you like with uv.

terminal
$ python3 --version
── expected output ──
Python 3.14.0

04Write hello.py

Make a folder for the course, for example python-course. Open it in VS Code (File → Open Folder), create a new file named exactly hello.py, type the line below and save.

If you use VS Code, install its Python extension when it offers to. Don't write code in Word or a rich-text editor: they add invisible formatting that Python cannot read.

hello.pywhole filepython
print("Hello, World!")

05Run it from the terminal

Open a terminal, move into your folder with cd, and run the file. In VS Code you can open a terminal already in the right folder with Terminal → New Terminal.

The interpreter starts, reads hello.py from top to bottom, runs each statement, and exits when it reaches the end. The terminal then shows its prompt again, ready for your next command.

terminal
$ cd python-course
python hello.py
── expected output ──
Hello, World!
Run it from the terminaldiagram
Rendering diagram…

06A slightly bigger first program

print can show several things at once: separate them with commas and it puts a space between them. It can show the result of arithmetic (+ adds, * multiplies). An empty print() prints a blank line.

A # starts a comment: a note for people, which Python ignores. Topic 0.6 covers comments.

hello.pywhole filepython
# My first real program
print("Hello! My name is Asha.")
print("I am learning", "Python", "today.")
print()
print("2 + 3 =", 2 + 3)
print("Days in a week times 2:", 7 * 2)

07Run from the editor too

With VS Code's Python extension installed, a Run triangle appears at the top right of a .py file. Clicking it types the same python hello.py command into a terminal for you.

Learn the terminal way first. When something goes wrong, knowing the actual command, the current folder and which Python is running is what lets you fix it.

Try it yourself

  1. 1

    Make it yours

    In the second example, change the name to your own and add one more print line that shows 10 - 4 = followed by the answer. Run it.

  2. 2

    Predict the blank line

    Still in the second example, add another empty print() at the very top. Before running, say how many blank lines the output will have and where.

  3. 3

    Run a file on your computer

    Install Python, create hello.py with the Hello, World! line, and run it from a terminal. Then change the file, save, and run the same command again (press the up-arrow key in the terminal to bring back the last command).

    terminal
    $ python hello.py
    ── expected output ──
    Hello, World!

Code & diagrams

Hello, World! New tab

The traditional first program. Change the text between the quotes and run it again.

Sign in to run this example in your browser.

Expected output

Hello, World!
Your first program, a little bigger New tab

Commas inside print put a space between the parts. An empty print() gives a blank line.

Sign in to run this example in your browser.

Expected output

Hello! My name is Asha.
I am learning Python today.

2 + 3 = 5
Days in a week times 2: 14
Install, check and run on your own computerbash

Type python3 instead of python on macOS and Linux.

# 1. check that Python is installed
python --version

# 2. go to your course folder
cd python-course

# 3. run your file
python hello.py

Output

Python 3.14.0
Hello, World!

Break it on purpose

Errors are the best teachers. Make each change, read the error, guess what went wrong, then reveal the answer.

Break #1

Run from the wrong folder (or misspell the file)

In a terminal, run python helo.py (one l), or run the right name from a folder that doesn't contain the file.

terminal
$ python3 helo.py
── what you'll see ──
python3: can't open file '/home/asha/python-course/helo.py': [Errno 2] No such file or directory

Break #2

Forget the quotes

In the first example, remove both quotation marks so the line reads print(Hello, World!) and run it.

main.pywhole filepython
print(Hello, World!)
terminal
$ python main.py
── what you'll see ──
File "main.py", line 1
print(Hello, World!)
^
SyntaxError: invalid syntax

Myth vs fact

Myth

I need a powerful computer to learn Python.

Fact

Any computer from the last ten years runs Python comfortably, and the first phases need only this web page. Heavy AI training needs strong hardware, but that is usually rented in the cloud, not owned.

Myth

I must install lots of tools before I can start.

Fact

You can start with only the Run button. On your own computer you need two things: Python and an editor.

Myth

python and python3 are different languages.

Fact

On current systems both run Python 3. The two names exist for historical reasons; use whichever your system provides.

Myth

Real programmers don't use the terminal any more.

Fact

Professional Python work is full of terminal commands: running programs, installing packages, running tests, starting servers. Getting comfortable with it early pays off.

Pro corner

Extra depth for experienced readers. New to this? Skip it for now and come back later.

  • ▸

    The Run button uses Pyodide: the real CPython interpreter compiled to WebAssembly, running inside your browser tab. (WebAssembly is a format that lets browsers run compiled programs.) The language is the same; the environment differs (no threads or processes, no real network sockets, an in-memory file system), and the lessons say so where it matters.

  • ▸

    On Windows, py is the Python launcher: py -3.13 hello.py picks a specific installed version, and py -0 lists the versions it can find. On macOS and Linux the same job is done by versioned commands such as python3.13.

  • ▸

    Avoid installing packages into the operating system's own Python on Linux and macOS: system tools depend on it, and recent systems block it with an "externally managed environment" error. Use a virtual environment or uv per project (Topics 6.5 and 6.6).

  • ▸

    python -c "print(2 + 3)" runs one line without a file, and python -m module_name runs a library module as a program. You will use -m constantly: python -m venv, python -m pytest, python -m http.server.

Remember this

  1. 1

    On this page, the Run button runs real Python (version 3.13) inside your browser. You can edit any example and run it again; your edits are saved in your browser. This is enough for most of the first five phases.

  2. 2

    On your computer, you install Python once from python.org (it is free). The installer gives you the interpreter: the program named python that reads your code and carries it out. Without an interpreter, a .py file is just text.

  3. 3

    You talk to the interpreter through a terminal: a window where you type commands. On Windows it is PowerShell or Terminal; on macOS it is Terminal; on Linux it is your terminal app. Typing python hello.py means: start the interpreter and give it the file hello.py to run.

  4. 4

    The command's name differs by system. On Windows it is python (and py, a small launcher that finds the newest installed Python). On macOS and Linux it is python3, because for years python meant Python 2 there and the names were kept apart for safety. This course writes python; type python3 if that is what your system uses.

  5. 5

    A Python program is a plain-text file whose name ends in **.py. Write it in a code editor, not a word processor. Visual Studio Code** (VS Code) is free and the most widely used; PyCharm is another good choice. An editor colours your code, indents for you and can run the file with one click.

  6. 6

    The terminal runs commands in a current folder. python hello.py only works if hello.py is in that folder, so you first move there with cd (change directory). The most common first-day error is being in the wrong folder.

Explain it without notes

01

What does the command python hello.py do, step by step?

02

Why is the command python3 on macOS and Linux but python on Windows?

03

The terminal says can't open file ... No such file or directory. Is your program wrong? What do you check?

04

What is the difference between a code editor and the interpreter?

Practice

01

Write a program that prints your name on the first line, your city on the second, a blank line, and then 7 * 6 = followed by the answer.

02

Write one print that shows Python is fun using three separate pieces of text separated by commas.

03

Write the three terminal commands, in order, to check the Python version, move into a folder called projects, and run app.py.

Trade-offs

  • ↔

    Browser Run button vs local Python. The browser needs no setup and can't break anything, but it has no keyboard input, no installed tools and no access to your files. Local Python has everything, at the cost of a one-time install.

  • ↔

    Terminal vs editor Run button. The editor's button is quicker; the terminal shows you exactly what is happening and works the same on every machine and server. Learn both, and reach for the terminal when confused.

Done when you can

  • Done when you have run and edited an example on this page.

  • Done when python --version (or python3 --version) prints a version on your computer.

  • Done when you have created hello.py and run it from a terminal.

  • Done when you can explain what the interpreter is.

  • Done when you know what to check when the terminal says the file cannot be found.