Python/gloss python class add methods
来自菜鸟教程
<languages />
Python添加类方法
添加方法
例
添加一个名为
welcome
到了
Student
类:
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)
如果在子类中添加与父类中的函数同名的方法,则父方法的继承将被覆盖。