Reputation: 3
So I'm currently learning Python's basics, using the book Python Crash Course. I'm on the chapter about classes, more precisely on the sub-class part of it. So first up, here's my code:
class Car():
"""une representation simpliste de voiture"""
def __init__(self, constructeur, annee, modele):
self.constructeur = constructeur
self.modele = modele
self.annee = annee
self.odometer_reading = 0
def descriptive_name(self):
long_name = str(self.annee) + ' ' + self.constructeur + ' ' + self.modele
return long_name.title()
def update_odometer(self, mileage):
"""set odometer reading"""
if mileage >= self.odometer_reading:
self.odometer_reading = mileage
else:
print("You can't roll back and odometer!\n")
def increment_odometer(self, miles):
self.odometer_reading += miles
def read_odometer(self):
"""print mileage"""
print("this car has " + str(self.odometer_reading) + " miles on it.\n")
class ElectricCar(Car):
def __init__(self, constructeur, annee, modele):
super().__init__(constructeur, annee, modele)
pass
my_tesla = ElectricCar('tesla', 'model s', 2016)
So, with this code I get this error message:
super().init(constructeur, annee, modele) TypeError: super() takes at least 1 argument (0 given)
The code I use is the same as in the book (except the french part, that are in english in the book). I tried with and without the "pass" of the "super()" and tried giving "super" the arguments "self" and "Car".
I'm using Python 3 and I'm on linux.
Thanks in advance for any answers :)
Upvotes: 0
Views: 192
Reputation: 203
The super() syntax is Python 3 If you're still using Python 2, you need super(ElectricCar, self)
Upvotes: 2