• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

python 类的继承

开发技术 开发技术 3小时前 2次浏览
class Ctc(object):
	def __init__(self):
		self.name = "shun"
	def run(self):
		self.prea()
		self.a()
		self.b()
		self.c()
	def a(self):
		print("a")
	def b(self):
		print("b")
	def prea(self):
		print("Prea")

class TestInstance(Ctc):
	def __init__(self):
		self.name = "shun2"
	def a(self):
		print("aa")
	def b(self):
		print("bb")

class Another(TestInstance):
	def __init__(self):
		self.name = "another"
	def a(self):
		print("aa in Another")
	# def b(self):
	# 	print("bb in Another")
	def d(self):
		print("d in Another")

class Case(Another):
	def __init__(self):
		self.name = "shun3"
	def c(self):
		print("cc in case")
	# def b(self):
	# 	print("bbb")
	# def run(self):
	# 	print("run in case")

if __name__ == '__main__':
	test = Case()
	exit(test.run())

  类的继承,会先找最底层的类是否有此函数,在找最接接近的类,直到最上层父类,就近原则


程序员灯塔
转载请注明原文链接:python 类的继承
喜欢 (0)