在 Python 中,使用关键字 class 定义一个类,在定义子类时在括号中指定父类即可实现继承。
示例:
class Parent:
def __init__(self, arg1, arg2):
self.arg1 = arg1
self.arg2 = arg2
def method1(self):
print("This is method1 in Parent class")
class Child(Parent):
def __init__(self, arg1, arg2, arg3