【新人求助】python 基类字典被无故覆盖
世纪代码太长,写了个类似的程序代码:
class A(): def __init__(self): pass def __del__(self): pass val={'1':'3'} class B(A): def __init__(self): pass def __del__(self): pass def set_val(self): for _key, value in self.val.items(): self.val['1'] = '4' b = B() a = A() print "A---",a.val print "B---",b.val b.set_val() print "A---",a.val print "B---",b.val结果:
A---{‘1’:‘3’}
B---{‘1’:‘3’}
A---{‘1’:‘4’}
B---{‘1’:‘4’}
为什么子类进行的字典操作,会影响基类?