Skip to main content
With your workspace open in VS Code, you are ready to write your first Python program. This page walks you through creating a .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.
Always include the .py extension when creating Python files. Without it, VS Code treats the file as plain text and none of the Python-specific features will work.

Write your first program

Click inside the editor and type the following:
Notice how VS Code immediately colours your code — 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: Press Ctrl + 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:
That single command tells your computer two things:
  1. python — launch the Python interpreter
  2. hello.py — read this file and execute the code inside it
You can run this command yourself directly in the terminal and get identical results. VS Code’s Run button is simply a shortcut around this fundamental operation.

How Python executes your code

Understanding Python’s execution model will save you many hours of debugging confusion later:
  1. 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.
  2. Interpretation — If the file passes the syntax check, Python converts your code into bytecode instructions.
  3. 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:
Python’s syntax check catches the error on line 3 before any code runs. You will see a 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 use python3 instead of python to ensure you are running Python 3:
VS Code’s interpreter selector handles this automatically once you have chosen your interpreter.

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.
Press Ctrl + ` (Windows/Linux) or Cmd + ` (macOS) to toggle the terminal panel open and closed without lifting your hands from the keyboard.

Experiment

Try modifying your file and running it again. Add more print() lines:
Each 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

Press Ctrl + 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.