-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex40.py
More file actions
32 lines (23 loc) · 1.12 KB
/
ex40.py
File metadata and controls
32 lines (23 loc) · 1.12 KB
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
class Song(object): # everything is some sort of subclass of object; object is
# the highest level class.
# the __init__ method is also known as the constructor
def __init__(self, lyrics):
self.lyrics = lyrics # This is assigning the given lyrics from the call
# `Song(lyric)` to the instatiation of Song we are making.
def sing_me_a_song(self):
for line in self.lyrics:
print(line)
# Study Drill 3: This is where your hacking would be, adding more methods
# to the class or instance variables in the __init__ method.
happy_bday = Song(["Happy birthday to you",
"I don't want to get sued",
"So I'll stop right there"])
bulls_on_parade = Song(["They rally around tha family",
"with pockets full of shells"])
# Study Drill 1: Songs go here
# Study Drill 2: The main reason it is preferred to use varibles is to make
# function call clearer. Another reason is that it allows Python to only send
# pointer (small index/location in memory) instead of the whole list of strings
# in the function call.
happy_bday.sing_me_a_song()
bulls_on_parade.sing_me_a_song()