The REPL is great for quick checks, but real programs live in files. A Python file ends in .py and contains one or more lines of code that run top to bottom.
Create a project folder
Pick a place for your course work. On macOS or Linux:
mkdir -p ~/code/python-fundamentals
cd ~/code/python-fundamentals
On Windows (PowerShell):
mkdir $HOME\code\python-fundamentals
cd $HOME\code\python-fundamentals
This is where every example in the course will live.
Write your first file
Open the folder in any text editor (we’ll set up VS Code in the next lesson) and create a file called hello.py. Put one line in it:
print("Hello, Python!")
Save the file.
Run the file
Back in the terminal, from inside the project folder, run:
uv run python hello.py
Hello, Python!
That’s it. The uv run python part starts Python, and hello.py tells it which file to execute. Python reads the file top to bottom and runs every line.
What happens if there’s an error?
Try changing the file to introduce a typo:
prnt("Hello, Python!")
Run it again:
uv run python hello.py
Traceback (most recent call last):
File "/Users/you/code/python-fundamentals/hello.py", line 1, in <module>
prnt("Hello, Python!")
NameError: name 'prnt' is not defined. Did you mean: 'print'?
This message is called a traceback. It tells you:
- Which file the error came from
- Which line failed
- What went wrong — Python doesn’t know what
prntis - A suggestion — “Did you mean
print?”
Python tries to be helpful when it can. We’ll cover tracebacks in detail in Section 15.
Fix the typo and run the file again to confirm it works.
A slightly longer program
Replace hello.py with:
name = "Python"
year = 1991
print(f"Hello, {name}!")
print(f"You were created in {year}.")
print(f"That makes you {2026 - year} years old.")
Run it:
uv run python hello.py
Hello, Python!
You were created in 1991.
That makes you 35 years old.
A few things you’ve now seen, all of which we’ll cover in detail later:
name = "Python"creates a variable holding textf"Hello, {name}!"is an f-string — a string that lets you insert variables with{...}2026 - yearis just maths, evaluated before being printed
Scripts vs modules
A Python file that’s meant to be run directly (like hello.py) is called a script. A Python file that’s meant to be imported and reused from another file is called a module. The same file can be both, depending on how you use it — we’ll see how in Section 11.
What’s next
You can write files and run them. Next, we’ll set up VS Code so writing those files is actually pleasant.