This reminded me of lvalue and rvalue in C++, so I asked if they were the same thing as store vs. load context. They were.
This one might need more clarification. I said they were the same idea, not the same thing. In a pointer-based language like C, a pointer is a kind of first-class integer value. You can pass them into and out of functions and you can use one as a store target in an assignment. You can even do arithmetic with them. Pointers are memory addresses.
However, in a memory-safe garbage-collected language like Python, references and values are categorically different things, so it’s incorrect to call store targets “values” at all. References are, of course, implemented using pointers behind the scenes, but references are not first-class values like a pointer would be. You can only store to locations, and you can’t directly pass around the location itself like a pointer value, although you can pass around container objects which have assignable locations. In Python, this usually means a dict (or an object backed by one), but there are a few other species, like lists. Dict keys and list indexes are values, but they aren’t locations by themselves. To be assignable, you have to combine them with their container.
It’s done this way so that an object’s memory can be instantly freed when the object has no more references. (And eventually freed when it’s no longer reachable. These can happen at different times when there are reference cycles.)
This one might need more clarification. I said they were the same idea, not the same thing. In a pointer-based language like C, a pointer is a kind of first-class integer value. You can pass them into and out of functions and you can use one as a store target in an assignment. You can even do arithmetic with them. Pointers are memory addresses.
However, in a memory-safe garbage-collected language like Python, references and values are categorically different things, so it’s incorrect to call store targets “values” at all. References are, of course, implemented using pointers behind the scenes, but references are not first-class values like a pointer would be. You can only store to locations, and you can’t directly pass around the location itself like a pointer value, although you can pass around container objects which have assignable locations. In Python, this usually means a dict (or an object backed by one), but there are a few other species, like lists. Dict keys and list indexes are values, but they aren’t locations by themselves. To be assignable, you have to combine them with their container.
It’s done this way so that an object’s memory can be instantly freed when the object has no more references. (And eventually freed when it’s no longer reachable. These can happen at different times when there are reference cycles.)