这里是一个小脚本:变量在Python
class Any(object):
def __init__(self,x):
self.x=x
l = [Any(2),Any(3),Any(7),Any(9),Any(10)]
print(len(l))
l2=[ind for ind in l]
l3=l
print(set(l2).difference(l3))
print(l2[1]==l[1])
print(l3[1]==l[1])
del l2[1]
print(len(l))
del l3[1]
print(len(l))
为什么删除的l2
Any
实例不会改变l
,但删除它l3
改变l
虽然它似乎没有L2之间有什么区别和l3?
非常感谢!
'l3'和'l'只是*相同*列表的两个名字... –
http://nedbatchelder.com/text/names.html – nmclean