Python教程

python 类的继承

本文主要是介绍python 类的继承,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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 类的继承的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!