Python Hello World with VS Code
( 48 Articles)
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
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:
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”:
If you’re using Python3, use this command instead:
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:
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.
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:
- Python: Checking System Default Encoding
- List, Dict, and Set Comprehensions in Python 3
- Python: Categorizing Given Words by Their First Letters
- Python 3: Simultaneously Iterating over Multiple Sequences
- VS Code: How to Pin/Unpin a File (2 Approaches)
- 2 ways to check your VS Code version