首页 > IT职业 > > 这样也可以,为什么非要@classmethod?
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/ ,如需转载,请注明出处,否则将追究法律责任。