.py file, understanding what happens when Python runs it, and using VS Code’s integrated terminal. These are the foundational habits you will use every single day as a Python developer.
Create a new file
1
Add a file to your project
In the Explorer panel on the left, click the New File icon (a page with a
+ symbol) and name the file hello.py. Press Enter to confirm.2
Confirm the .py extension
Make sure the filename ends in
.py. This extension tells VS Code and Python that the file contains Python code, which activates syntax highlighting and all the Python extension features.Write your first program
Click inside the editor and type the following:print is highlighted as a built-in function, and the text inside the quotes appears in a distinct colour. This is syntax highlighting, and it helps you spot typos and errors at a glance.
The
print() function is one of the most frequently used tools in Python. It displays any value or text you pass to it in the terminal. You will use it throughout this course to inspect what your code is doing.Select a Python interpreter
Before running the file, confirm VS Code knows which Python to use.1
Open the Command Palette
Press
Ctrl + Shift + P (Windows/Linux) or Cmd + Shift + P (macOS).2
Select an interpreter
Type Python: Select Interpreter and press
Enter. Choose the Python version you installed. It will appear in the status bar at the bottom of VS Code once selected.For now you are selecting your system-wide Python installation. Later in the course you will learn to use virtual environments, where each project gets its own isolated Python interpreter.
Run your program
There are three equivalent ways to run your file: Method 1 — Run button: Click the ▶ triangle in the top-right corner of the editor, or click the dropdown arrow and choose Run Python File. Method 2 — Right-click menu: Right-click anywhere in your code and select Run Python File in Terminal. Method 3 — Keyboard shortcut: PressCtrl + F5 (Windows/Linux) or Cmd + F5 (macOS).
The terminal panel opens at the bottom and shows your output:
What is happening behind the scenes?
When you click Run, VS Code executes this command in the terminal on your behalf:python— launch the Python interpreterhello.py— read this file and execute the code inside it
How Python executes your code
Understanding Python’s execution model will save you many hours of debugging confusion later:- Syntax check — Python reads the entire file first and checks for syntax errors. If it finds any, it stops immediately and prints an error message. No code runs at all.
- Interpretation — If the file passes the syntax check, Python converts your code into bytecode instructions.
- Line-by-line execution — Python runs those instructions from top to bottom, left to right.
Python always executes code top to bottom. The order of your statements matters — what you write first happens first.
What a syntax error looks like
Consider this broken file:SyntaxError in the terminal, and none of the three lines will produce output — not even the correct ones. This surprises many beginners, but it is intentional: Python will not run a file it cannot fully parse.
python vs python3
On macOS and Linux, you may need to usepython3 instead of python to ensure you are running Python 3:
Using the integrated terminal
The terminal panel at the bottom of VS Code is a fully functional shell — identical to opening a separate Terminal or Command Prompt window. You can type commands directly in it.Experiment
Try modifying your file and running it again. Add moreprint() lines:
print() call produces one line of output. This is the feedback loop you will use constantly as you build more complex programs.
Save your work
PressCtrl + S (Windows/Linux) or Cmd + S (macOS) to save. A dot next to the filename in the tab indicates unsaved changes — save frequently so you never lose your work.
Course resources
Download all practice notebooks, exercise files, and cheat sheets.