Skip to content

Setting Variables

In this activity, we explore variables. A key concept in any coding language is that of a variable. When data is saved in a program, it is referred to as a variable and may be referenced by one or more variable names.

These variable names allow us to access, alter, or use the stored data in calculations. Variables are therefore central to writing useful programs because they allow information to be stored and reused.

What is a Variable?

A variable is a named location used to store data in a program. Once a value has been assigned to a variable, the variable name can be used later in the code to refer back to that value.

Why Variables Matter

Variables make code more flexible and easier to understand. Instead of repeating values throughout a program, you can store a value once and refer to it by name whenever it is needed.

Exercise: Setting Variables

You now have an opportunity to write and test your own code. Please use Anaconda and Jupyter Notebook to complete the exercise.

Run your code and save the file. You may also want to make note of the steps you followed, the results you obtained, and any errors you encountered.