Create your first Python application
With Python and Python tools installed, you can create your first Python application! In this exercise, you'll create an empty folder, open the folder in Visual Studio Code, and then create your first application.
Step 1 - Start VS Code in a project folder
Many projects start with an empty folder, which is how you'll start yours.
In Visual Studio Code, open a new Terminal window by selecting Terminal > New Terminal.
Create an empty folder called "hello-world", navigate into it, and open VS Code (code) in that folder (.) by entering the following commands:
Create a new folder called hello-world:
md hello-world
Navigate to the hello-world folder:
cd hello-world
Open Visual Studio Code in that folder:
code .
Create a new folder called hello-world:
mkdir hello-world
Navigate to the hello-world folder:
cd hello-world
Open Visual Studio Code in that folder:
code .
Create a new folder called hello-world:
mkdir hello-world
Navigate to the hello-world folder:
cd hello-world
Open Visual Studio Code in that folder:
code .
Tip
Open the command prompt or terminal as administrator to run
code .
Alternatively, you can run VS Code through the operating system UI, then use File > Open Folder to open the project folder.
Step 2 - Create a new Python file and add code
With Visual Studio Code open to your empty folder, you'll now create a Python file to display the message Hello, World.
In the Explorer view, HELLO_WORLD panel, hover over the title bar, and then select New File.
Name the new file hello.py by entering it into the new textbox, and pressing Enter.
By using the
.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.Enter the following Python code in the editor panel. This command uses the
print
function to display the text Hello, World! when your application is run.print('Hello, World!')
Save the file by selecting File and Save (or Ctrl+S).
Step 3 - Run your application
Since it's a single line program, you can actually run your application from inside Visual Studio Code.
Open the built-in terminal in Visual Studio Code by selecting View and Terminal.
In the new terminal window, run the following command to run your Python code.
python hello.py
python3 hello.py
python3 hello.py
Hello, World! appears in the terminal window. Congratulations! You've created a Python application!