Running Python Code
Let's get Python up and running.
Hello, World!
As per tradition, let's start by creating a "Hello, World!"-program. This is a simple program that just prints (i.e. displays) the string (i.e. text) "Hello, World!" somewhere, often a terminal.
To stay organized you should first create a folder in a suitable location on your computer and name it something nice.
I've created a folder on my computer called my-python-stuff.
- Open VS Code
- In VS Code, open the File menu and select Open Folder...
- Find and choose the folder you just created.
Now we're going to create a Python file with some code and run it.
TODO: Add screenshots or video.
- Click the New File... icon on the left (hover over
MY-PYTHON-STUFF) - Create a new file called
hello.py - Add the line
print("Hello, World!")to the file and save - Now VS Code will hopefully notice that you've added a Python file and ask if you want to install the Python extension. Do that.
- If it says "Python 3.11.0" in the bottom bar of the GUI (graphical user interface), you're good. If it instead says something like "Select interpreter", click that and manually locate the Python interpreter on your file system.
- In the top bar, click "View" -> "Terminal"
-
Type
python hello.pyand press ENTER (if you have a Mac remember that you might have to writepython3instead)
Congratulations! You ran code!
Next: Syntax