+ 1
Can somebody explain me the code below ? I am having special trouble understanding the role of super function here.
Why does the super function here takes argument ? And where are the objects of the class Hero created , in the __init__ function itself ? Somebody make this code easy for me .Thanks https://code.sololearn.com/cvT5Sq0GWTfc/?ref=app
3 Respuestas
+ 6
In Python 2.xx you need to pass the parent Class name and self explicitly.
In Python 3.xx this is valid, but not necessary as they will already be passed implicitly.
0
okay, but in all other examples that I have seen. super took no arguments. it was usually written as-
super().__init__(x, y) but in this exapmle it has Hero in the parenthesis. Why ?
0
Yeah ! I understand now. Thanks Jan and chaotic. However, there's one thing I still don't understand. How is the object of class hero is created ? super(Hero,self).__init__(name,10,2). I have never seen anyone put values in __init__ arguments . Is this also exclusive to python 2 or it's something else.