-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.py
47 lines (41 loc) · 1.91 KB
/
demo.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
class A_CLASS:
def whoAreYou(self):
return 'a class'
class ANOTHER_CLASS:
def whoAreYou(self):
return 'another class'
class A_DERIVED_CLASS(A_CLASS):
def whoAreYou(self):
return 'A class that derives from ' + super().whoAreYou()
class ANOTHER_CLASS(ANOTHER_CLASS):
def whoAreYou(self):
return 'Another derived class that derives from ' + super().whoAreYou()
types = (A_CLASS ,
ANOTHER_CLASS ,
A_DERIVED_CLASS,
ANOTHER_CLASS)
objects = [ obj() for obj in types ]
for o in objects:
for t in types:
if isinstance(o, t):
print(o.whoAreYou(), 'is an instance of', t.__name__)
else:
print(o.whoAreYou(), 'is not an instance of', t.__name__)
#
# a class is an instance of A_CLASS
# a class is not an instance of ANOTHER_CLASS
# a class is not an instance of A_DERIVED_CLASS
# a class is not an instance of ANOTHER_CLASS
# Another derived class that derives from another class is not an instance of A_CLASS
# Another derived class that derives from another class is an instance of ANOTHER_CLASS
# Another derived class that derives from another class is not an instance of A_DERIVED_CLASS
# Another derived class that derives from another class is an instance of ANOTHER_CLASS
# A class that derives from a class is an instance of A_CLASS
# A class that derives from a class is not an instance of ANOTHER_CLASS
# A class that derives from a class is an instance of A_DERIVED_CLASS
# A class that derives from a class is not an instance of ANOTHER_CLASS
# Another derived class that derives from another class is not an instance of A_CLASS
# Another derived class that derives from another class is an instance of ANOTHER_CLASS
# Another derived class that derives from another class is not an instance of A_DERIVED_CLASS
# Another derived class that derives from another class is an instance of ANOTHER_CLASS
#