This post has to do with Python variable binding (the way I understand it).
All variables are binded (point) to an object or None.
Everything is an object (numbers, strings, classes, modules, functions,etc.)
A variable can point to any type of object.
Some objects are mutable (can be changed); some are immutable (cannot be changed).
Example mutable objects: lists, dictionaries
Example immutable objects: strings, numbers of any type , tuples
x = 1 ( var x points to integer object with value of 1)
x= x + 1 ( var x points to a different integer object with value of 2)
The original object x was bound to is now unbound and will be removed by the garbage collector.
If x pointed to a list object and it was changed, x would still point to the same object.
Variables as function parameters:
- A pointer is passed to the original object for each parameter.
- If the parameter object is immutable, then any changes will cause creation of a new object.
- The variable used in the calling statement will still point to the original (unchanged) object.
- If the parameter object is mutable, then any changes will affect the original object.
- The variable used in the calling statement will see affects of the changes made.