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

what is the problem with the super() function ?

Sayse
  • 42,633
  • 14
  • 77
  • 146
npkp
  • 1,081
  • 5
  • 18
  • 24
  • replace `super()` by the name of your superclass, i. e. `car`. Or if you want `super`, `super(electricCar, self).__init__(make, model, year)` – AdrienW Jul 29 '16 at 08:11
  • What version of Python are you using? You can see the `super()` syntax in [official docs](https://docs.python.org/2/library/functions.html#super) . For Python 2 you need to specify the child class name as the type argument. For Python3 you don't – RedBaron Jul 29 '16 at 08:11
  • If you are just learning the language... why are you starting with a python version that is *6 years old*? Just start with the newest versions. Python2 should be used only by people who need it for backwards compatibility with old systems/libraries. – Bakuriu Jul 29 '16 at 08:37

3 Answers3

8

super() (without arguments) was introduced in python3 Here is python2 implementation.

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

you could refer this question for general inheritance syntax issue regarding python2 and python3

Community
  • 1
  • 1
mehari
  • 3,057
  • 2
  • 22
  • 34
3

It looks like you are trying to use the Python 3 syntax, but you are using Python 2. In that version you need to pass the current class and instance as arguments to the super function:

super(electricCar, self).__init__(make, model, year)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
0

If you are using python 2 you need to pass your instance explicitly with the super method. In python 3 or higher, instance variable are passed implicitly you don't need to specify it. Here self is an instance of the class car

super(car, self).__init__(make, model, year)
Projesh Bhoumik
  • 1,058
  • 14
  • 17