The complexity of the following scenario has left me utterly perplexed:
x = 5
y = x
z = x
z = z + 1
results in
x = 5
y = 5
z = 6
However, when dealing with arrays, as seen below:
x = ["z", "x", "y"]
y = x
z = x
z = z.sort()
results in
x = ["x", "y", "z"]
y = ["x", "y", "z"]
z = ["x", "y", "z"]
It seems that changing a value in a variable only affects that specific variable - which makes sense. But when using methods like .sort(), it appears to impact other variables in a surprising way due to some sort of intricate reassignment logic. Can someone shed light on this for me? I feel completely disoriented and find it rather counterintuitive.