py06_08-2:类方法

 

 

 

 

 

 

 

 

 

class Person(object):
    count = 0

    @classmethod
    def show_people_count(cls):
        print('显示创建的人数:%s' % cls.count)

    def __init__(self, name):
        self.name = name
        Person.count += 1


P1 = Person('yeyu')
Person.show_people_count()
上图代码

 

posted on 2020-03-25 17:16  yeyu1314  阅读(86)  评论(0编辑  收藏  举报