注册 登录
编程论坛 Python论坛

python提示出错:TypeError: object() takes no parameters。哪位大神帮忙一下,哪儿错了! 非常感谢。

thermoswd 发布于 2020-05-31 10:30, 1728 次点击
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=str(self.year)+' ' +self.make+' ' +self.model
     return long_name.title()
     
   def read_odometer(self):
     print("This car has "+ str(self.odometer_readming)+" miles on it. ")
     
   def update_odometer(self,mileage):
     if mileage>=self.odometer_reading:
      self.odometer_reading=mileage
     else:
      print("You can't roll back an odometer!")
      
class ElectricCar(Car):
   """电动汽车的独特之处"""
   
   def _init_(self,make,model,year):
      """初始化父类的属性"""
      super()._init_(make,model,year)
      
my_tesla = ElectricCar('tesla','models',2016)
#'tesla','model s',2016
print(my_tesla.get_descriptive_name())

提示出错信息:
Traceback (most recent call last):
 File "hello_word.py", line 30, in <module>
  my_tesla = ElectricCar('tesla','models',2016)
TypeError: object() takes no parameters

1 回复
#2
thhkb2020-06-01 09:50
def __init__
1