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:
We name the folder as hello
and open it (the hello
folder is your workplace):
Then we select New File
button create a new file in hello folder, name it hello.py
, and it automatically opens in the editor:
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.
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.
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):
Hello World!