I have this bit of code
def find():
temp = liked
shuffle(temp)
if temp == liked:
return True
By debugging I've seen that after shuffle(temp) also the liked variable changes. Why does it happen?
I have this bit of code
def find():
temp = liked
shuffle(temp)
if temp == liked:
return True
By debugging I've seen that after shuffle(temp) also the liked variable changes. Why does it happen?
temp = liked
is an assignment. It points temp
to liked
so that when you say shuffle(temp)
, temp
is just referring shuffle()
back to liked
.
assignment: temp = liked
copy: temp = liked.copy()
You will find an in depth conversation about it here: Does Python make a copy of objects on assignment?