http://learnpythonthehardway.org/book/ex40.html
将歌词放在一个单独的变量中,然后将该变量传递给该类以代替使用。
我不明白该怎么做,我什至不完全确定他的意思。他的意思是在类中定义变量吗?
class Song(object):
def __init__(self, lyrics):
self.lyrics = lyrics
def sing_me_a_song(self):
for line in self.lyrics:
print line
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 the family",
"With pockets full of shells"])
happy_bday.sing_me_a_song()
bulls_on_parade.sing_me_a_song()