Our first few examples will involve less code than "how-to" knowledge: how to run Python, how to get a Python interpreter on your computer, etc.

The simplest expression

The very first thing we did with Python was evaluate expressions. The very simplest expression, the first one that we’ll show in class, is an integer literal value, e.g.:

42

When we type this into a Python interpreter, it should tell us that the value of 42 is, well, 42!

Evaluating expressions in Python

As described on the Tools page, I suggest taking a phased approach to playing with Python, starting with a simple approach and getting more sophisticated over time:

  1. Start out with the online Python interpreter Python Morsels or OnlineGDB.

  2. Next, install Thonny, a Python interpreter designed for learning.

  3. Later, think about using a full-fledged IDE (integrated development environment).

Online Python interpreter

After opening the Python Morsels REPL, we can type a single expression into the prompt and press Enter. This will show what our expression evaluates to (in this case, the number 42).

Evaluating our simple expression in an online REPL
Figure 1. Evaluating our simple expression in the Python Morsels REPL

Thonny

To evaluate our expression in Thonny, type the expression into the "Shell" box at the bottom of the app and press Enter.

Evaluating our simple expression in Thonny
Figure 2. Evaluating our simple expression in Thonny

IDE

Following Microsoft’s Getting started with Python in VS Code tutorial will help you install VS Code, Python and the VS Code Python Extension. Once you’ve done that, you should be able to start the Python interpreter by opening the Command Palette and searching for "REPL", as shown in Starting the Python interpreter in VS Code.

Starting the Python interpreter in VS Code
Figure 3. Starting the Python interpreter in VS Code

After starting the Python interpreter, you should see a Python prompt (>>>) in the Terminal at the bottom of your VS Code window. Click inside this window, type 42 and press Enter, as shown in Evaluating our simple expression in VS Code.

Evaluating our simple expression in VS Code
Figure 4. Evaluating our simple expression in VS Code

Further expressions

We can, of course, evaluate more complex expressions too! Some examples are shown in Evaluating more interesting expressions. Note that I’m using yet another Python interpreter in this example, so the prompts and results are styled differently, e.g., In [1] instead of >>>, but the results of evaluating the expressions should be the same for any Python 3 interpreter.

Evaluating our simple expression in VS Code
Figure 5. Evaluating more interesting expressions

The first three expressions mean exactly what they mean in mathematics. The fourth expression is a bit different; you don’t need to understand it just yet. We will, however, get there!