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.

2.1 Variables

As in other programming languages, variables are used to store data of different values or types (hence the name variable). In Python, you declare a variable by writing its name and then assigning its value with the equal (=) sign:

When naming variables, there are a few rules to keep in mind:

Notice that when we initialize a variable, we do not need to specify its type (e.g. it being an integer or a string), as Python is dynamically typed, which means it figures out your desired variable type by itself once you run the program. This means, you can also simply overwrite your previously created variable with for example a character string:

If you want to know what’s currently stored in your variable, you can use the print() function:

Hello World

Note: If you are working in an interactive environment like the Jupyter notebooks which we will use in the exercises, you might not even need to write print as the last line of the code cell is automatically evaluated.