1class test:
2 def __init__(self, *args):
3 print(f"called test with: {args}")
4
5class testing(test):
6 def __init__(self, *args):
7 print(f"Called testing with: {args}")
8 super().__init__(*args)
9
10testing("hmm")
11# super is a keyword that calls the parent class
1# It's kinda hard to explain this just by code.
2# So I'll provide a link to a pretty good explanation of it.
3https://www.pythonforbeginners.com/super/working-python-super-function
1class Foo(Bar):
2
3 def __init__(self, *args, **kwargs):
4 # invoke Bar.__init__
5 super().__init__(*args, **kwargs)
1class Square(Rectangle):
2 def __init__(self, length):
3 super().__init__(length, length)
1# The super() function lets you run a parent class function inside the child class.
2class Parent(object):
3 def __init__(self, age):
4 self.age = age
5
6 def func(self):
7 print(f"Hi, my age is {self.age}!")
8
9class Child(Parent):
10 def __init__(self, age):
11 # Here is where I can use the super to run the parent class __init__ function to set the childs' name
12 super().__init__(age)
13
14dad = Parent(36)
15kid = Child(8)
16
17dad.func()
18kid.func() # The kid inherits it from the dad, so I could run it like that too