作者: LP_ProgramLife | 来源:发表于2018-01-19 11:42 被阅读6次

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()

相关文章

网友评论

      本文标题:

      本文链接:https://www.haomeiwen.com/subject/ucsooxtx.html