The following code (python3) prints 5 and not 4.
x = 5
y = x
x = 4
print(y)
But every now and I find a situation where the opposite behavior occurs, where a variable is assigned to some location in memory rather than the value stored there. A few times I have found a bug in my code because of something like this.
Is there a similar situation to the above code (and in Python), in which a beginner might intend for the code to store the current value of one variable in a new variable, but instead of the value it assigns the identifier? Also, I don't mean to impose any specific data type by the words "value" and "variable" here, so my apologies if these terms are not correct.
If there are some comments about how this behavior varies over some common languages (esp. python, javascript, java, c, haskell), I would be interested to hear about that. And of course, any suggestions on what is appropriate terminology for this question (and how to tag it) would be kindly appreciated as well.
EDIT: I'm accepting an answer which describes how the behavior varies with immutable/mutable types as this is likely the behavior I had encountered, and I had asked in particular about a source of confusion for a beginner programmer. However, someone visiting this page with a similar question should refer also to the comments section which indicates that a general answer isn't as simple as mutable/immutable data types.
x = somethingyou always create a new reference, even if that something is of a mutable type. It is better to read a few introductory articles then experiment yourself.