现在的位置: 首页 > 综合 > 正文

第一个python类的实现

2018年04月03日 ⁄ 综合 ⁄ 共 322字 ⁄ 字号 评论关闭
[zcm@python #105]$cat a.py
#!/usr/bin/python

class Simple:
	def __init__(self, name):
		self.name = name
	
	def hello(self):
		print self.name + " says hi."

class Simple2(Simple):
	def goodbye(self):
		print self.name + " says goodbye."

me = Simple2("Tim")
me.hello()
me.goodbye()
[zcm@python #106]$

运行结果:

[zcm@python #106]$./a.py
Tim says hi.
Tim says goodbye.
[zcm@python #107]$

抱歉!评论已关闭.