学习Python艰难的方式ex40,我不理解__init__部分

时间:2015-01-05 11:46:40

标签: python oop python-2.7

我很难理解在学习Python困难之路的练习中第3-4行发生的事情。

1 class Song(object):
2
3     def __init__(self, lyrics): # This part
4         self.lyrics = lyrics
5
6     def sing_me_a_song(self):
7         for line in self.lyrics:
8             print line
9
10 happy_bday = Song(["Happy birthday to you",
11                    "I don't want to get sued",
12                    "So I'll stop right there"])
13
14 bulls_on_parade = Song(["They rally around the family",
15                         "With pockets full of shells"])
16
17 happy_bday.sing_me_a_song()
18
19 bulls_on_parade.sing_me_a_song()
我一遍又一遍地阅读练习,但我不明白发生了什么。为什么这两个论点?为什么格式化为self.lyrics?

0 个答案:

没有答案