Python 中的类的继承

class parent(object):
	def override1(self):
		print("Parent")
		
class child(parent):
	def override2(self):
		print("Child")
		
		
dad=parent()
son=child()

dad.override1()

son.override1()

son.override2()

输出结果:

Parent
Parent
Child
class parent(object):
	def altered(self):
		print("Parent altered()")
		
class child(parent):
	def altered(self):
		print("Child,Before Parent altered()")
		super(child,self).altered()
		print("Child,After Parent altered()")
		
dad=parent()
son=child()

dad.altered()
son.altered()

运行结果:

Parent altered()
Child,Before Parent altered()
Parent altered()
Child,After Parent altered()

  

  

posted @ 2019-05-14 15:50  华小电  阅读(356)  评论(0编辑  收藏  举报