创建子类时出错 TypeError: object.__init__() takes exactly one argument (the instance to initialize)

pangzhuzhuzhu 2021-09-01 10:51:12

我把代码简化一了下 新人求指导 感谢 🧎‍♀️

class Car:
    def __init___(self, make, model, year):
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0

    def get_descriptive_name(self):
        long_name = f"{self.year} {self.model} {self.year}"
        return long_name.title()

class ElectricCar(Car):
    def __init__(self, make, model, year):
        super().__init__(make, model, year)

my_tesla = ElectricCar('tesla', 'model s', 2019)
print(my_tesla.get_descriptive_name())

报错:TypeError: object.__init__() takes exactly one argument (the instance to initialize)

初始化子类属性时super的使用那行 以及 创建特定对象 my_tesla(倒数第二行)那行出错

求解答

 

 

 

 

 

 

...全文
1908 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
mrdongwd 2021-12-22
  • 打赏
  • 举报
回复 1

第二行,__init___这里多写了一个“_”

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧