Python Programming from First Principles: Learn to Code, Think Computationally, and Solve Real-World Problems
PDFEPUB
CHAPTER GUIDE · GETTING STARTED

First Python file

On this pageCreate hello.pyWrite and save the programRun the fileChange and run againIf the result is different

A Python file stores instructions so that the same program can be run again. Keep first-python-file-demo open in VS Code and use the interpreter selected on the preceding page.

Create hello.py

  1. In Explorer, move the pointer over the project folder and select New File, the page-with-a-plus icon shown in Figure 8.1
  2. Enter hello.py and press Enter. Check that the name appears in both Explorer and the editor tab.
  3. Keep the .py ending: hello.py.txt is a different filename. The language indicator should identify the file as Python.
Official VS Code Explorer screenshot highlighting New File and a filename field containing hello.py.
Figure 8 — Create hello.py with Explorer’s New File control. The official example folder is named HELLO and includes a .venv folder; use first-python-file-demo here. A .venv folder is not required for this first example.

Write and save the program

  1. Enter this single line in hello.py:
print("Hello World!")
Listing 22 — A saved program that displays one message.
  1. Save with Ctrl+S on Windows/Linux or Command+S on macOS. If a Save dialog appears, save inside first-python-file-demo.
  2. Check the editor tab: the unsaved-change dot should disappear after saving.
macOS Save dialog showing hello.py and the practice folder.
Figure 9 — Save hello.py in the practice folder. Captured on the author’s Mac; other operating systems use a different Save dialog.

print() displays the message between quotation marks. The quotation marks are part of the instruction, not part of its output.

Run the file

  1. Keep hello.py open and saved.
  2. Open the Command Palette and choose Python: Run Python File in Terminal. Alternatively, use the Run Python File play button at the editor’s upper right, shown in Figure 10.
  3. Look at the Terminal panel that opens below the editor. The Python extension starts the selected interpreter and runs the file.
Official VS Code screenshot highlighting the Run Python File play button above a Python editor.
Figure 10 — Run Python File is the play button at the editor’s upper right. The official screenshot uses a different example message; keep the Hello World program shown in this book.

The program’s output should be exactly:

Hello World!
Listing 23 — Expected program output.

The terminal may also show a command, an interpreter path and a prompt. These identify the execution session; they are not additional output from print().

Change and run again

  1. Change the message to Hello from my first file!.
  2. Save the file and run it with the same command.
  3. Check that the terminal displays the new message. This confirms that the editor is running the saved file you changed.

The same program can be launched from a terminal in its project folder with python hello.py, provided the intended Anaconda environment is active. The editor’s Run Python File command is the simpler route for this first example.

If the result is different

  • No run command: check that Microsoft’s Python extension is enabled and the file ends in .py.
  • No interpreter: repeat Python: Select Interpreter from the preceding page.
  • SyntaxError: compare the quotation marks and parentheses with the example above.
  • The old message remains: save the file and confirm that the active tab is hello.py in the intended project.
  • File not found in a manual terminal run: open the correct project folder before entering the command.

The two projects that follow use the same cycle—write, save, run and inspect—to produce greetings and a short timeline.


  1. Microsoft, Python in VS Code. Source of the New File and Run Python File screenshots; execution instructions checked on 22 October 2026. These screenshots are from official documentation, not the author’s computer.↩︎