问答详情
源自:3-2 Python继承类

大家注意上面的super方法时python2的方法,python3 跟python2的super 方法不一样。

python2 :

Teacher(Person):
    (namegendercourse):
        (Teacher,).__init__(namegender)
        .course = course


python3:

Teacher(Person):
    (gendercourse):
        ().(.namegender)
        .course = course


提问者:慕村8238729 2022-10-04 15:15

个回答

  • 慕田峪6554729
    2024-10-22 00:38:58

    #请参考Student类,编写Teacher类,老师拥有任教某个科目的属性。 class Students: def __init__(self, name, gender,score ): self.name = name self.gender = gender self.score = score class Taecher (Students): def __init__(self,name,gender,score,account): super().__init__(name,gender,score) self.account=account def get_info (self): return self.name,self.gender,self.score,self.account tt=Taecher("张三","女",90,"语文") print(tt.get_info())

  • 時頌望見
    2023-12-10 20:41:55

    😥...

  • 风再起时2019
    2023-03-04 12:18:09

    😥...