python 列表中插入自定义类的疑惑

Python 2.7.4 (default, Apr 19 2013, 18:32:33)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Person:                                #我自定义的类
...     def setname(self,name):
...             self.name=name
...
>>> list=[ ]                                            #建立一个空列表
>>> temp=Person()
>>> temp.setname('a')
>>> list.append(temp)
>>> list[0].name
'a'                                                        #将temp追加到list中后,list[0].name 的值为‘a’
>>> temp.setname('b')
>>> list.append(temp)
>>> list[0].name                                  #经过上两步后,居然list[0]和list[1] 的值都改变了
'b'
>>> list[1].name
'b'
>>> del temp                                     #删除之前存在的temp后,又重新定义一个,就没有问题了
>>> temp=Person()
>>> temp.setname('c')
>>> list.append(temp)
>>> list[0].name
'b'
>>> list[1].name
'b'
>>> list[2].name
'c'
>>>

原文地址:https://www.cnblogs.com/tcstory/p/3320615.html