1、继承
"""继承"""
class Father(object):
def father_study(self):
"""
学习羽毛球
:return:
"""
sport = '学习羽毛球'
return sport
class Child(Father):
def child_study(self):
"""
继承父亲的学习方向
:return:
"""
return super().father_study()
child = Child()
print(child.child_study())
运行结果:
D:\Study\pythonProject\venv\Scripts\python.exe D:/Study/pythonProject/PythonBasic/Test1203.py
学习羽毛球
Process finished with exit code 0
2、导包继承
父类:
"""继承"""
class Father(object):
def father_study(self):
"""
学习羽毛球
:return:
"""
sport = '学习羽毛球'
return sport
子类继承父类:
"""导包、继承"""
from PythonBasic.Test1203 import Father
class Child(Father):
def child_study(self):
"""
继承父亲的学习方向
:return:
"""
return super().father_study()
child = Child()
print(child.child_study())
运行结果:
D:\Study\pythonProject\venv\Scripts\python.exe D:/Study/pythonProject/PythonBasic/Test1204.py
学习羽毛球
Process finished with exit code 0
3、抛异常
"""抛异常"""
try:
print('需要执行的代码')
except:
print('如果存在异常,执行本代码')
else:
print('如果无异常,执行本代码')
finally:
print('无论有没有异常,均执行代码')
3万+

被折叠的 条评论
为什么被折叠?



