2006年11月07日 星期二 18:15
ΪʲôÕâ¶Î´úÂëµÄÊä³ö×îºó¾¹È»ÓÐÎÊÌ⣿ 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
Zeuux © 2025
京ICP备05028076号