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)亲自试一试 »如果在子类中添加与父类中的函数同名的方法,则会覆盖父方法的继承。
