ITPub博客

首页 > IT职业 > > 这样也可以,为什么非要@classmethod?

这样也可以,为什么非要@classmethod?

作者:znsk07 时间:2019-04-12 16:38:07 0 删除 编辑

class Person(object):

    count = 0

    def how_many():

        return Person.count

    def __init__(self, name):

        self.name = name

        Person.count = Person.count + 1


print (Person.how_many())

p1 = Person('Bob')

print (Person.how_many())


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27/viewspace-3142237/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-11

  • 博文量
    114
  • 访问量
    653