⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objvar.py

📁 《简明 Python 教程》为 "A Byte of Python" 的唯一指定简体中文译本
💻 PY
字号:
#!/usr/bin/env python
# Filename: objvar.py

class Person:
	'''Represents a person.'''
	population=0

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

		#When this person is created, he/she adds to the population
		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 people left.' %Person.population
	
	def sayHi(self):
		'''Greeting by the person.

		Really, that's all it does.'''
		print 'Hi, my name is %s.' %self.name
	
	def howMany(self):
		'''Prints the current population.'''
		if Person.population==1:
			print 'I am the only person here.'
		else:
			print 'We have %d persons here.' %Person.population

swaroop=Person('Swaroop')
swaroop.sayHi()
swaroop.howMany()

kalam=Person('Abdul Kalam')
kalam.sayHi()
kalam.howMany()

swaroop.sayHi()
swaroop.howMany()
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -