Set up your editor

You now have a terminal and Python on your computer. This page adds the editor you will write your code in. Think of it as Microsoft Word for programs: see The tools programmers use if you want the longer comparison.

Install VS Code

  1. Download VS Code from code.visualstudio.com and install it on your own computer. This is a normal install, like any other app.
  2. Open VS Code and choose File, Open Folder. Pick the python-projects folder you made earlier (~/Projects/python-projects).

Here is roughly what you will see. Your copy may use a lighter color theme and show a Welcome tab, but the parts are the same:

A mock code editor. A file panel on the left lists the python-projects folder. The open file, hello.py, has line numbers, colored code, and a red squiggle under prnt, a misspelling of print. Four numbered notes explain these.

VS Code and your terminal look at the same folder. A file you create in VS Code shows up when you type ls in the terminal, and the other way round.

Write a Python file

  1. In the Explorer panel on the left, hover over the folder name and click the New File icon. Type a name ending in .py, such as hello.py, and press Enter.

  2. Type this line into the file:

    print("Hello")
  3. Save it with Ctrl+S on Windows or Cmd+S on Mac. Saving matters: the terminal runs the saved version of the file, not what is on screen.

Recall

Why do you save a file before running it in the terminal?

Show the answer

The terminal runs the saved version of the file, not what is on the screen.

Run it in the terminal

Open your terminal and move into ~/Projects/python-projects. Check that the file arrived, then run it with python:

~/Projects/python-projects $ ls
hello.py
~/Projects/python-projects $ python hello.py
Hello

The word python starts the interpreter, and hello.py tells it which file to read. The output appears right under the command. If your program asks for input, type your answer in the terminal and press Enter.

Recall: click each blank to check yourself

In python hello.py, the word starts the interpreter, and tells it which file to read.

To change the program, edit the file in VS Code, save it, and run the same command again. Press the Up arrow to bring the command back without retyping.

Check that it works

Your first project does this for you: Your first Python file. If it runs and prints your color, Python and your terminal are working.

Projects

Practice what you learned in your own editor. Each project has its own page.