Part 1 of the How to Write Code series.
This page shows the shortest possible path from an empty computer to a running program.
- Python 3.8 or newer installed (check with
python --version) - A text editor (VS Code recommended) or any browser-based Python editor
- About 10 minutes
Create a folder called learn-code, then inside it create a file named hello.py.
The .py ending tells the computer the file contains Python code.
print("Hello, World!")print() is a built-in function that sends whatever is inside the brackets to the screen. Text must be wrapped in quotes — that is called a string.
Open a terminal in the same folder and run:
python hello.pyYou should see:
Hello, World!
If you instead see python: command not found, try python3 hello.py (common on macOS and Linux).
Now accept input from the user:
name = input("What is your name? ")
print(f"Hello, {name}! Welcome to programming.")Run it:
python hello.pyWhat is your name? Rita
Hello, Rita! Welcome to programming.
The f"..." prefix creates an f-string, which lets you drop variables directly into text with {}.
git init
git add hello.py
git commit -m "Add first Python program"Now your work has a saved history you can return to.
| Message | Cause | Fix |
|---|---|---|
SyntaxError: invalid syntax |
Missing closing quote or bracket | Count your quotes |
command not found: python |
Python not on PATH | Use python3 instead |
FileNotFoundError |
Wrong folder | cd into the folder that holds the file |
Continue to Variables, data types and operators.