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
- Download VS Code from code.visualstudio.com and install it on your own computer. This is a normal install, like any other app.
- Open VS Code and choose File, Open Folder. Pick the
python-projectsfolder 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:
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
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 ashello.py, and press Enter.Type this line into the file:
print("Hello")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.
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.