Python 添加类方法
添加类方法
实例
向 Student 类添加一个名为 welcome 的方法:
class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.graduationyear = year
def welcome(self):
print("Welcome", self.firstname, self.lastname, "to the class of", self.graduationyear)
如果您在子类中添加了一个与父类中的函数同名的方法,那么将会覆盖父类方法的继承。