码迷,mamicode.com
首页 > 编程语言 > 详细

python 类变量与实例变量,可变对象与不可变对象的实践

时间:2019-08-02 11:23:29      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:end   test   set   process   elf   style   exe   code   with   

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

 

python 类变量与实例变量,可变对象与不可变对象的实践

标签:end   test   set   process   elf   style   exe   code   with   

原文地址:https://www.cnblogs.com/bowanghou/p/11286859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!