Can somebody explain me the code below ? I am having special trouble understanding the role of super function here. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

19th May 2018, 12:23 AM
Masquerade
Masquerade - avatar
3 Answers
+ 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.
19th May 2018, 12:56 AM
ChaoticDawg
ChaoticDawg - avatar
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 ?
19th May 2018, 12:43 AM
Masquerade
Masquerade - avatar
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.
19th May 2018, 1:20 AM
Masquerade
Masquerade - avatar