Getting started with Python

Christopher Af Bjur

June 11th, 2020

This is a tutorial on getting started with Python.


Installing Python

Installation

First we will need to grab the latest version of Python. You can download it from here. Start the installation by clicking on the newly downloaded file and proceed with the installation wizard untill the installation is finished.

If you're on Windows it's very important that you check the "Add Python x.x to PATH" checkbox when walking through the Python installation wizard. If you don't do this, things will not work as expected while following this tutorial.

Confirmation

Next, we'll want to confirm that Python was installed correctly. I'll describe how to do it both for Mac and for Windows.

Mac

Press CMD + Space to open up Spotlight and type terminal and press enter in order to open up a new terminal window. Here we type python3 and press enter.

terminal

python3

This command should output some information about the python version that we previously installed. Press CTRL + D to exit.

Note that we can also type python but that will output information about the python version that comes pre-installed with Mac or Linux, which is not what we're looking for here.

Windows

Click on the search bar in the bottom left of your desktop. Type cmd which is short for "Command Prompt" and press enter. When the command prompt opens, type python and press enter.

terminal

python

You should see some output in the command prompt with information about the currently installed Python version, which should be equivalent to the version that we previously installed. When can then press CTRL + Z to exit.


Writing our first program

So the time has come for us to write our first Python program. Cool! But before we do that we will want to install a code editor or IDE of our choice. In this tutorial we will be using the code editor VSCode. It rocks!

Start off by initializing an empty project and create a new file called app.py

Visual Studio Code Python project

In this file we'll write our first Python program. Let's use one of the built in Python methods called print.

app.py

print("Hello world!")

Save the changes then open up a terminal window at the project root or VS Code's integrated terminal and run the following command:

terminal

python3 app.py

The terminal should now print out "Hello World".

Congratulations! You've now setup Python on your machine and created your first Python program.

CODICULUM

©2020-present Christopher af Bjur. All Rights Reserved.