(python)每日代码||2024.1.27||类方法与实例方法

class test():
    aaa = 111
    bbb = 222
    ccc = 333
    @classmethod
    def cm(cls):
        cls.aaa="***"
    
    def im(self):
        self.aaa="iii"
    
aa = test()
print(aa.aaa,aa.bbb,aa.ccc)#111 222 333
aa.im()
print(aa.aaa,aa.bbb,aa.ccc)#iii 222 333

aa=test()
print(aa.aaa,aa.bbb,aa.ccc)#111 222 333
test.cm()
print(aa.aaa,aa.bbb,aa.ccc)#*** 222 333
aa=test()
print(aa.aaa,aa.bbb,aa.ccc)#*** 222 333
posted @ 2024-01-27 15:11  Kazuma_124  阅读(18)  评论(0编辑  收藏  举报