Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Python is a very versatile programming language and can especially be used for scientific programming and image processing. Python’s syntax is very similar to Matlab’s one. Before beginning this lab, you may need to read Paragraph.

First, boot your computer on Ubuntu, then open Jupyter Lab or VSCodium.

Using Jupyter Lab

Jupyter Lab runs in a web browser.

  • Open a terminal by typing terminal in the main menu or typing Ctrl + Alt + T.

  • Start Jupyter by typing in a terminal:

    jupyter lab

    or

    jupyter-lab
Using VSCodium
  • Open the main menu and type VSCodium to start the sotware.

Now you are ready to write a Python program in the notebook.

  • In the first cell of the notebook, write

    40 + 2

    and type Shift + Return. The code is executed, the result is displayed then a new cell appears below.

  • Like any programming language, the code is written using variables and functions. A variable stores one (or more) values, whether it is numeric or not. The name of the variable can contain letters, numbers (except the first character) or underscore. Case is important (i.e. a and A are two different variables). Type the instructions below in the second cell:

    year = 2026
    course = "BIP"

    and type again Shift + Return. Now the value 2026 is stored in the variable year and the character string “BIP” is stored in the variable course.

  • Modify the previous cell by adding the following statement:

    print(f"{course} {year}")

    print is a function and the string in the brackets is an argument. Here, this argument is a character string. The f at the beginning of the string means that it is a formatted string. Type Shift + Return to run again the code.

A notebook is appealing as it is also possible to add text using the markdown language.

  • Select an empty cell, then click on the drop-down list in the toolbar to select Markdown. Then you can write formatted text. Try to write:

    New exercise

    Write bold, italic or equations: 2\sqrt{2}.

    This can be useful for inserting titles or keeping comments and notes.

Verify your code in the correction below.


Correction

Objectives

  • Discover and know how to write a Python program.

  • Discover and know how to use a notebook.

  • Write by using the markdown syntax.

  • Manipulate variables.

Code cells

The two cells containing codes should be:

42
BIP 2026

Markdown cell

The markdown cell should be:

## New exercise

Write **bold**, *italic* or equations: $\sqrt{2}$.

to get:

New exercise

Write bold, italic or equations: 2\sqrt{2}.