TypeError: Super does not take Key word arguments?

三世轮回 提交于 2019-12-03 02:03:39

The arguments to the parent's __init__ method should be passed to the __init__ method:

super(Kidnappers, self).__init__(name="The Kidnappers", hp=30, damage=7)
# or
super(Kidnappers, self).__init__("The Kidnappers", 30, 7)

All you pass to super() is the child class (Kidnappers in this case) and a reference to the current instance (self).


Note however that if you are using Python 3.x, all you need to do is:

super().__init__("The Kidnappers", 30, 7)

and Python will work out the rest.


Here are some links to where this is explained in the documentation:

Option # 1 : Python 2.7x

Here you can pass self keywork to super() which inherently refers the instance properties.

super(self, name="Wild Boar", hp=10, damage=2).__init__()

Option # 2 : Python 3x

super() no longer need to any parameters and you can simply write

super().__init__("The Kidnappers", 30, 7)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!