class Person:
population =0
def __init__(self,name):
"Initiaalizes the person's data."
self.namea = name
print("initializing",self.namea)
Person.population +=1
def __del__(self):
"I am dying"
print("say bye",self.namea)
Person.population -=1
if Person.population ==0:
print("I am the last one.")
else:
print("There are still %d people left",Person.population)
def sayHi(self):
"Greeting by the person.Really,that'sall it does."
print("Hello,this is ",self.namea)
def howmany(self):
"Prints the current population."
if Person.population ==1:
print("I am the last one")
else:
print("we have %d person here ",Person.population)
p = Person("xiaoming")
p.sayHi()
p.howmany()
k =Person("kkk")
k.sayHi()
k.howmany()
p.sayHi()
p.howmany()
网友评论