Python Class Foundation

1380 ワード

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)