طريقة إضافة فئة بايثون
طرق إضافة
مثال
أضف طريقة تسمى 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)
إذا أضفت عملية في الصنف الفرعي بنفس اسم دالة في الصنف الأصل ، فسيتم تجاوز وراثة الطريقة الأصل.