class car(object):
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
self.odometer_reading = 0
class electricCar(car):
def __init__(self, make, model, year):
super().__init__(make, model, year)
tesla = electricCar('tesla', 'model s', 2016)
print tesla.get_descriptive_name()
Run Code Online (Sandbox Code Playgroud)
TypeError:super()至少需要1个参数(给定0)
super()函数有什么问题?
super()(没有参数)是在python3中引入的.
这是 python2实现.
class electricCar(car):
def __init__(self, make, model, year):
super(electricCar,self).__init__(make, model, year)
Run Code Online (Sandbox Code Playgroud)
你可以参考这个问题来获得关于python2和python3的一般继承语法问题
| 归档时间: |
|
| 查看次数: |
5258 次 |
| 最近记录: |