Python Class Foundation
# -*- coding: cp936 -*- class Person: """代表一个人""" population = 0 def __init__(self,name): """初始化""" self.name = name print "初始化,%s" % self.name Person.population +=1 def __del__(self): "I 'm dieing" print "%s says byebye" %self.name Person.population -= 1 if Person.population == 0: print "no one left" elif Person.population >=1: print "there are %s person left" %Person.population def sayHi(self): """person say hi""" print "%s says hi" % self.name @staticmethod def howMany(self): """how many person left""" if Person.population ==1: print "only me left" elif Person.population >=1: print "there are %s person left" % Person.population andy = Person("andy") tom = Person("Tom") Person.howMany(andy)