Home>

Currently, I'm studying Python from the basics with the aim of getting a Python certification, and most recently I'm trying to figure out about class inheritance.

The code that describes the original class and the inherited class is as follows.

#Class inheritance
"" "
Create a new class with the originally created class as the parent class.
In addition to inheriting the contents of the parent class with a certain grammar, the child class defines a new class.
"" "
class FavChara:
    def __init __ (self, title, name):
        self.title = title
        self.name = name

class NeoFavChara:
    def __init __ (self, title, name, prime):
      super () .__ init __ (title, name)
      self.prime = prime

classes = []
classes.append (NeoFavChara ('Dragon Ball','Son Gohan','Son Goku'))
classes.append (NeoFavChara ('One Piece','Usopp','Luffy'))
classes.append (NeoFavChara ('One Punch Man','Saitama','Saitama'))
classes.append (NeoFavChara ('The Promised Neverland',' Emma',' Emma'))
classes.append (NeoFavChara ('Kimetsu no Yaiba','Kamado Nezuko','Kamado Kanjiro'))

for eachCls in classes:
  print ("" + eachCls.title + ""'s favorite character: "+ eachCls.name +" (the main character is "+ eachCls.prime +") ")


However, when I ran this with "IDLE (Python 3.8 64-bit)",

Traceback (most recent call last):
  File "C: \ Users \ user \ Desktop \ PythonTrials \ izm06.py", line 78, in<module>
    classes.append (NeoFavChara ('Dragon Ball','Son Gohan','Son Goku'))
  File "C: \ Users \ user \ Desktop \ PythonTrials \ izm06.py", line 74, in __init__
    super () .__ init __ (title, name)
TypeError: object.__init__ () takes exactly one argument (the instance to initialize)

I get the error, and I can't get to the point where I can output all the contents of the inherited class in the character string.

https://www.tutorialfor.com/go.php?id=157952 First in class from the answers to the questioninitI came up with the possibility that the number of arguments set with is not the same as the number of arguments used at the time of calling, but I still do not know what kind of description should be used to set the arguments. ..

I know that it happened because of a trivial problem, but if anyone knows it, please answer again this time.