Person.count+=1为什么不能写成self.count+=1 ?
class Person(): count=0 def __init__(self,name): self.name=name Person.count+=1 #为什么这里不可以用self.count+=1? p1=Person('xiaoming') p2=Person('hanmeimei') p3=Person('xiaoli') print(p3.count)
class Person(): count=0 def __init__(self,name): self.name=name Person.count+=1 #为什么这里不可以用self.count+=1? p1=Person('xiaoming') p2=Person('hanmeimei') p3=Person('xiaoli') print(p3.count)
2020-03-12
举报