-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathfirst_classes.py
More file actions
40 lines (29 loc) · 910 Bytes
/
first_classes.py
File metadata and controls
40 lines (29 loc) · 910 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
class Parent:
"""docstring for Parent"""
CLASS_CONSTANTS = ["a", "b", "c"]
def __init__(self, eye_color, hair_color="brown"):
self.eye_color = eye_color
self.hair_color = hair_color
def do_something(self):
print("Do something, Parent")
def something_else(self):
print("Do something else, Parent")
class Child(Parent):
"""docstring for Child"""
def __init__(self, number_of_toys, *args):
Parent.__init__(self, *args)
self.number_of_toys = number_of_toys
def do_something(self):
print("Do something, Child")
dad = Parent("green", "brown")
son = Child(5, "blue", "blonde")
mom = Parent("blue")
daughter = Child(3, "black")
print(dad.eye_color)
print(son.eye_color)
print(son.number_of_toys)
print(mom.hair_color)
print(daughter.hair_color)
son.do_something()
dad.do_something()
son.something_else()