-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathin.py
More file actions
41 lines (29 loc) · 679 Bytes
/
in.py
File metadata and controls
41 lines (29 loc) · 679 Bytes
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
"""
in.py
Chapter 6 Object Oriented programming
Author: William C. Gunnells
Rapid Python Programming
"""
class First(object):
n = 0
def __init__(self, color='red'):
self.color = color
def hello1(self):
print("Hello from first class!")
def color_method(self):
print("My color from first class", self.color)
class Second(First):
def hello2(self):
print("Hello from second class!")
print(self.n, "is my favorite number")
a0 = First()
a0.color_method()
print('-------')
a1 = First(color='blue')
a1.hello1()
a1.color_method()
print('-------')
a2 = Second(color='white')
a2.hello1()
a2.hello2()
a2.color_method()