Python论坛  - 讨论区

标题:[python-chinese] (无主题)

2006年11月07日 星期二 18:15

iamzcyhit iamzcyhit在gmail.com
星期二 十一月 7 18:15:41 HKT 2006

ΪʲôÕâ¶Î´úÂëµÄÊä³ö×îºó¾¹È»ÓÐÎÊÌ⣿
class Person:
    '''Represents a person.'''
    population = 0

    def __init__(self,name):
        '''Initializing the person's data.'''
        self.name = name
        print '(Initializing %s)' %self.name

        Person.population += 1
    def __del__(self):
        '''I am dying'''
        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 person left' %Person.population
    def sayHi(self):
        '''Greeting by the person.
        really,that's all it does.'''
        print 'hello,I am %s' %self.name
    def howMany(self):
        '''print the current population.'''
        if Person.population == 1:
            print 'I am the only person here'
        else:
            print 'We have %d persons' %Person.population

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

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

iamzcy.sayHi()
iamzcy.howMany()





iamzcyhit
2006-11-07
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061107/46c0fe6f/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号