Python 类示例

来源:互联网 发布:企业移动办公软件 编辑:程序博客网 时间:2024/05/16 14:54
class Person:    population = 0     def __init__(self , name):        self.name = name         print '(Initializing %s)' % self.name        Person.population += 1    def __del__(self):        print '%s says bye.' % self.name        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):        print 'Hi ,my name is %s' % self.name    def howMany(self):        if Person.population == 1:            print 'I am the only person here.'        else:            print 'We have %d person here.' % Person.populationhan = Person('han')han.sayHi()han.howMany()shuo = Person('shuo')shuo.sayHi() shuo.howMany() 
0 0
原创粉丝点击