python 类变量与实例变量,可变对象与不可变对象的实践
class E:
    s=''
    d=[]
    def __init__(self):
        self.dd=[]
aa=E()
aa.d.append('abc')
aa.dd.append('abc')
aa.s+='abc'
print(aa.d)
print(aa.dd)
print(aa.s)
print('='*20)
print(E.d)
print(E.s)
print('='*20)
aa=E()
aa.d.append('123')
aa.dd.append('123')
aa.s+='123'
print(aa.d)
print(aa.dd)
print(aa.s)

输出:

D:\Python37\python.exe D:/study____/PIC/test_import/a/a.py
['abc']
['abc']
abc
====================
['abc']

====================
['abc', '123']
['123']
123

Process finished with exit code 0

结论:

可变对象:list dict set

不可变对象:tuple string int float bool

 

posted on 2019-08-02 09:58  旧楚布衣  阅读(299)  评论(0编辑  收藏  举报