-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoop18 (quick tips).py
59 lines (41 loc) · 942 Bytes
/
oop18 (quick tips).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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# OOP quick tips
# Tip 1
# printing the children classes of Parent class.
# Parent classes
class Father:
def __init__(self):
value=0
def update(self):
value+=1
def renew(self):
value=0
def show(self):
print(value)
class Mother:
def __init__(self):
value=1
def update(self):
value-=1
def renew(self):
value=0
def show(self):
print(value)
# Children classes
class Child_1(Father):
def update(self):
value+=2
class Child_2(Mother):
def update(self):
value-=2
# the main function.
def interiors(*classx):
subclasses=set()
work=[*classx]
while work:
parent=work.pop()
for child in parent.__subclasses__():
if child not in subclasses:
subclasses.add(child)
work.append(child)
return subclasses
print(interiors(Father,Mother))