반응형
class Parent:
def can_sing(self):
print('Sing a song')
class LuckyChild(Parent):
pass
class UnluckyChlid:
pass
class LuckyChild2(Parent):
def can_dance(self):
print('Shuffle Dance')
father = Parent()
father.can_sing()
child = LuckyChild()
child.can_sing()
child2 = UnluckyChlid()
print(child.__dir__())
print(child2.__dir__())
child3 = LuckyChild2()
child3.can_dance()
child3.can_sing()
실행결과
$ py inheritance.py
Sing a song
Sing a song
['__module__', '__doc__', 'can_sing', '__dict__', '__weakref__', '__repr__', '__hash__', '__str__', '__getattribute__', '__setattr__', '__delattr__', '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__init__', '__new__', '__reduce_ex__', '__reduce__', '__subclasshook__', '__init_subclass__', '__format__', '__sizeof__', '__dir__', '__class__']
['__module__', '__dict__', '__weakref__', '__doc__', '__repr__', '__hash__', '__str__', '__getattribute__', '__setattr__', '__delattr__', '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__init__', '__new__', '__reduce_ex__', '__reduce__', '__subclasshook__', '__init_subclass__', '__format__', '__sizeof__', '__dir__', '__class__']
Shuffle Dance
Sing a song
반응형
'Programming > Python' 카테고리의 다른 글
[Python-Basic] Class Data Type - 4(Self) (0) | 2019.11.05 |
---|---|
[Python-Basic] Class Data Type - 4(Namespace) (0) | 2019.11.05 |
[Python-Basic] Class Data Type - 3(Constructor) (0) | 2019.11.05 |
[Python-Basic] Class Data Type - 2(Instance) (0) | 2019.11.05 |
[Python-Basic] Class Data Type - 1 (0) | 2019.11.05 |