Skip to content

Commit cc435a7

Browse files
author
Vitalii Cherkashyn
authored
abstract class, method
1 parent ddfdb3f commit cc435a7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

class-abstract.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import abc
2+
from abc import ABC
3+
4+
class Parent(ABC):
5+
6+
@abc.abstractmethod
7+
def who_am_i(self):
8+
return "parent"
9+
10+
11+
class Child(Parent):
12+
13+
def who_am_i(self):
14+
return "child"
15+
16+
if __name__=="__main__":
17+
print(Child().who_am_i()) # child
18+
print( issubclass(Child, Parent) ) # True
19+
print( isinstance(Child(), Child) ) # True
20+
print( isinstance(Child(), Parent) ) # True
21+
print( isinstance(object(), Parent) ) # False
22+
# Parent() - can't create abstract class

0 commit comments

Comments
 (0)