In Python, there are two spaces, the namespace and the object space.
Names are just labels you assign to objects, which live in the object space. Objects have values and types; names are just there for our convenience; so that we may access things in the object space.
This is different than other languages like C where the variable is more like a box in which you can put a certain type of thing.
In Python, names can point to any object of any type - they are just aliases.
When you assign a name to an object, like this:
a = 1
a
is just a label that points to the object 1
that has a type (int) and a value. If you next do this:
b = 1
Now you have two names a
and b
pointing to the same object - they are not "copies", but just two labels to the same object.
When you do this:
a = 'hello'
Now a
is pointing to a new object, but b
is still pointing to the old object (1
).
Eventually, when no names are pointing to objects, Python does automatic garbage collection to keep the object space optimized.