gpt4 book ai didi

python super()函数错误?

转载 作者:行者123 更新时间:2023-12-05 08:33:32 28 4
gpt4 key购买 nike

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()

TypeError: super() takes at least 1 argument (0 given)

super() 函数有什么问题?

最佳答案

super()(无参数)在 python3 中引入 这是 python2 实现。

class electricCar(car):
def __init__(self, make, model, year):
super(electricCar,self).__init__(make, model, year)

你可以引用this question关于 python2python3

的一般继承语法问题

关于python super()函数错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38653667/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com