This page goes over inheritance of object between classes in Python. This is a big part of OOP and making reusable code.
super().__init__()
Supercharge Your Classes With Python super() – Real Python
Python’s super() considered super!
class SuperClass:
def __init__(self, money, hourly):
self.money = money
self.hourly = hourly
def show_stats(self):
return print('Money is {} and your hourly is {}'.format(self.money, self.hourly))
class SubClass(SuperClass):
def __init__(self, money, hourly):
super().__init__(money, hourly)
def yea(self):
return SuperClass.show_stats(self)
S = SubClass('$300', '$50500')
S.yea()
Seems to do the same thing as Ex. 1, but at least I wrote it myself. I am still now 100% what it does, other than inheriting objects from another class to then use in the subclass, but I can see how this can be useful. I am going to see if I can use this in my EP 425 final project (see EP 425 Semester Project and Project Code Notes)
super().__init__(money, hourly)
, you are pretending that you are inserting those inputs in the parent class, so then the parent class will have all the goods even thought you inputted them from the subclass.__init__(self, money, hourly)
since you are now “initializing” them from the child class.
Python Class Inheritance: A Guide to Reusable Code - Codefather