Python Hello World with VS Code

Last updated on February 9, 2022 A Goodman Loading... Post a comment

In this short article, you will learn how to write your first lines of Python code and run them in 2 different ways:

  • Using the built-in terminal of the VS Code.
  • Using the Python extension

Prerequisites: Make sure Python and VS Code are already installed on your computer. You can download Python from python.org and download VS Code from code.visualstudio.com.

Python Hello World Example

1. Create a new folder (the name is totally up to you) and open it with VS Code.

2. Create a new file named index.py inside the folder you’ve recently created. Add the following code to it:

print("Hello World!")

Running Python code using command-line

1. Press “Ctrl” + “`” or select “View” > “Terminal” to open the built-in terminal of the VS Code (there is no difference between Windows and macOS). After that, enter the command below then press “Enter”:

 python index.py

If you’re using Python3, use this command instead:

 python3 index.py

Screenshot:

2. You’ll see something similar to this:

Executing Python code with the Python extension

1. Select the Extensions tab from the left-hand Activity bar, head to the search box, and search for the extension:

@id:ms-python.python

At the time of writing, the Python extension for VS Code has gained more than 50 million of downloads:

Click the Install button to install the extension. Reload (or restart) your VS Code to make sure everything is ready.

2. Now when you open your Python file, you will see a little play button in the top right corner:

Click that button to execute your code.

3. Output:

Final Words

That’s it, my friend. This tutorial may be basic and boring for you, but from here, you’re pretty good to go. Continue learning more about Python and other interesting programming stuff by taking a look at the following articles:

You can also check out our Machine Learning category page or Python category page for more tutorials and examples.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles