Variables

A basic introduction to the concept of variables in Python.

A variable is a reserved memory location to store values. You identify these memory locations with variable names.

name = "Robert"
print(name)

Here I'm using the = or 'assignment' operator to assign the value of "Robert" to the variable called name. I'm then outputting the value of this variable to the console, as was done in the previous section using the print() function.

Each variable has its own scope, where scope refers to the visibility of variables. In other words, which parts of the program can see or use it.

You can't get the value of a variable earlier than the line in which it was defined.

Last updated