I'll explain the relationship between objects and names. That is, I'll explain aliasing.
In Python, we create objects and give them names. It's important to understand objects, names, and their relationship to each other-- at the very least it will help you avoid some bugs!
We create objects to represent data. For example, when we execute a = [4, 25]
, Python sees the [4, 25]
and creates a list object.
When we create an object, we want to be able to refer back to it later. So we make a name that points to it. Above, we made the name a
and pointed it at a list object. Then, when we use that name in a statement, Python finds the object that it points to so we can do things with the object-- like printing its value or modifying its data. For example, to execute a.append(400)
, Python looks at the name a
, finds the object that it points to (the list), and then modifies the list by appending the value 400
to it.
We're allowed to have multiple names point to a single object. For example, we c