Variables

We will begin our study of Python by learning how to save data into an object called a variable. Let's start with giving a definition.

A variable is a named storage location in a computer's memory that can hold data.

We will go into computer memory in depth later, for now, think of computer memory as a huge shelf-case and variables as labeled containers on these shelves. Variables let us put data in these containers and give each container a name for easy reference. Most of the time, we can change what's inside these containers after we've initially put something in them. These containers are also handy for storing and organizing large amounts of data.

Let's make our first variable! We can create a variable using the assignment operator, more commonly known as the equal (=) symbol. In the following code editor try running the code and see what happens. Feel free to try changing the value to a different number.

Where did all of this text come from? Well, behind the scenes we added some extra code. By itself, the code x = 3 does not display anything. In the next code block we add the code we hid before. The print function displays text to the console. We will learn more advanced uses of this function in the Prints - formatting lesson. Until then, we will use it to display both text and variables by passing these into the print function separating them with commas.