python 类中 self 和 类本身变量的区别

2025-03-01 03:33:15
推荐回答(1个)
回答1:

  def __del__(self):
        '''I am dying.'''
        print '%s is dying ' %self.name
        print '%s says bye.' % self.name
        self.__class__.population -= 1
        if self.__class__.population == 0
            print 'I am the last one.'
        else:
            print 'There are still %d people left.' % self.__class__.population

......

Jack = Person('Jack')
Jack.sayHi()
Jack.howMany()

Tom = Person('Tom')
Tom.sayHi()
Tom.howMany()
Jack.sayHi()
Jack.howMany()