PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Seb The S
# inheritance from template class
class Template:
def __init__(self, **kwargs):
# using only keyword arguments here
self.common = kwargs['common']
self.answer = kwargs['answer']
def show_answer(self):
# some shared diagnostics
print('-'*20)
print(self.__class__)
print(self.common)
print(f'The answer is {self.answer}')
class Extension(Template):
def __init__(self, **kwargs):
# consume anyhing that's not needed by superclass
self.extra = kwargs.pop('extra')
# pass the rest to super constructor
super().__init__(**kwargs)
def additional_method(self):
print(f'My extra argument is {self.extra}')
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run