petit_herisson

导航

Exercise 40 - class

 

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()

output

Happy birthday to you
I don't want to get sued
So I'll stop right there
They rally around the family
With pockets full of shells

 

2019-10-01

17:04:15

posted on 2019-10-01 12:04  petit_herisson  阅读(144)  评论(0)    收藏  举报