1.实例变量:作用于实例的内部,可以在实例化之后进行增删改。
2.类变量:类中自带的变量,当实例未对类变量重新赋值就直接调用时,会直接查找到类中变量的内存地址。
测试用例如下
# Author:soap class test: n = 123 n_list = [] def __init__(self,name): self.name = name r1 = test('soap') r2 = test('Dylan') r1.n = 'r1' print(r1.n,r2.n,test.n) r1.n_list.append('from r1') r2.n_list = ['from r2'] print(r1.n_list,r2.n_list,test.n_list)