Tutorial 4: Run Python Hello World

May 20, 2022

Step 1: Create Python Hello World Source Code File

Remember the step 4 in Tutorial 1, how we open a folder. By starting VS Code in a folder, that folder becomes your workspace.

Here we create a new foler under Desktop: hellofolder

We name the folder as hello and open it (the hello folder is your workplace): hellofolder

Then we select New File button create a new file in hello folder, name it hello.py, and it automatically opens in the editor: hellofolder

By using th .py file extension, you tell VS Code to interpret this file as a Python program, so that it evaluates the contents with the Python extension and selected Python interpreter.

Let’s try to print a messgae in hello.py:

msg = "Hello World"
print(msg)

When you start typing print or msg, notice how IntelliSence from Python Extension presents auto-completion options.

auto

auto

It works for standard Python modules and other packages you have installed into the environment of the selected Python interpreter. It also provides completions for methods available on object types, we will learn that from future class.

Step 2: Run Python Hello World

To run the hello.py, just click the Run Python File button in the top-right side of editor. run

The button opens a terminal panel in which your Python interpreter is automatically activated, then runs python3 hello.py (macOS.Linux) or python hello.py(Windows):

run

Hello World!

comments powered by Disqus