forked from DarkMemem/PythonIntro09
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inheritance.py
56 lines (41 loc) · 970 Bytes
/
inheritance.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
class WaterBird:
def __init__(self, name):
self.name = name
print('Bird is {} ready.'.format(self.name))
def where_is_live(self):
print('On the Earth')
def swim(self):
print('Can swim fast')
def voice(self):
pass
class Penguin(WaterBird):
def __init__(self, name):
WaterBird.__init__(self, name)
print('Penguin is ready')
def where_is_live(self):
print('North Pole')
def run(self):
print('Run fast')
def voice(self):
print('Pi-pi-pi')
class Duck(WaterBird):
def __init__(self, name):
super().__init__(name)
print('Duck is ready')
def where_is_live(self):
print('Anywhere')
def fly(self):
print('Fly')
def voice(self):
print('Kra-kra-kra')
p = Penguin('Ping')
p.where_is_live()
p.swim()
p.run()
p.voice()
print('-' * 50)
d = Duck('Donald Dug')
d.where_is_live()
d.swim()
d.fly()
d.voice()