Compare if two variables reference the same object in python

后端 未结 6 1240
别跟我提以往
别跟我提以往 2021-01-30 06:29

How to check whether two variables reference the same object?

x = [\'a\', \'b\', \'c\']
y = x                 # x and y reference the same object
z = [\'a\', \'b         


        
6条回答
  •  轮回少年
    2021-01-30 06:56

    I really like to have a visual feedback, that's why I sometimes just open up http://www.pythontutor.com/visualize.html#mode=edit to see how the memory is allocated and what is referencing what.

    Added this awesome gif as this reply is about visualizing..

提交回复
热议问题