ویژگی ها را اضافه کنید(Add Properties)


مثال


Add a property called graduationyear to the
Student class:



class Student(Person):
  def __init__(self, fname, lname):
   
super().__init__(fname, lname)
    self.graduationyear
= 2019




در مثال زیر، سال 2019 باید یک متغیر باشد و به
کلاس دانش آموز هنگام ایجاد اشیاء دانشجویی.
برای انجام این کار، پارامتر دیگری را در تابع __init__() اضافه کنید:




مثال


Add a year parameter, and pass the correct
year when creating objects:



class Student(Person):
  def __init__(self, fname, lname, year):
   
super().__init__(fname, lname)
    self.graduationyear
= year

x = Student("Mike", "Olsen", 2019)