Is it possible to reassign the value referenced to by a variable, rather than the variable itself?
a = {"example": "foo"}
b = a
When I reassign a
, it is reassigning the variable a to reference a new value. Therefore, b
does not point to the new value.
a = {"example": "bar"}
print(b["example"]) # -> "foo"
How do I instead reassign the value referenced by a? Something like:
*a = {"example": "bar"}
print(b["example"]) # -> "bar"
I can understand if this isn't possible, as Python would need a double pointer under the hood.
EDIT Most importantly, I need this for reassigning an object value, similar to JavaScript's Object.assign
function. I assume Python will have double pointers for objects. I can wrap other values in an object if necessary.