What is the name of what the list is doing to the variable x to prevent it from being bound to any changes to the original value of x? Shielding? Shared structure? List binding? Nothing is coming back from a Google search using those terms.
Because the list isn't doing anything, and it isn't a property of collections.
In Python, variables are names.
>>> x = 5
This means: x
shall be a name for the value 5
.
>>> l = [x]
This means: l
shall be a name for the value that results from taking the value that x
names (5
), and making a one-element list with that value ([5]
).
>>> x += 1
x += 1
gets rewritten into x = x + 1
here, because integers are immutable. You cannot cause the value 5
to increase by 1, because then it would be 5
any more.
Thus, this means: x
shall stop being a name for what it currently names, and start being a name for the value that results from the mathematical expression x + 1
. I.e., 6
.
That's how it happens with reference semantics. There is no reason to expect the contents of the list to change.
Now, let's look at what happens with value semantics, in a hypothetical language that looks just like Python but treats variables the same way they are treated in C.
>>> x = 5
This now means: x
is a label for a chunk of memory that holds a representation of the number 5
.
>>> l = [x]
This now means: l
is a label for a chunk of memory that holds some list structure (possibly including some pointers and such), which will be initialized in some way so that it represents a list with 1 element, that has the value 5
(copied from the x
variable). It cannot be made to contain x
logically, since that is a separate variable and we have value semantics; so we store a copy.
>>> x += 1
This now means: increment the number in the x
variable; now it is 6
. The list is, again, unaffected.
Regardless of your semantics, you cannot affect the list contents this way. Expecting the list contents to change means being inconsistent in your interpretations. (This becomes more obvious if you rewrite the code to l = [5]; x = l[0]; x += 1
.)