首页 > 其他 > 详细

Exercise 40 - class

时间:2019-10-01 12:48:00      阅读:108      评论:0      收藏:0      [点我收藏+]

 

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 dont want to get sued
So Ill stop right there
They rally around the family
With pockets full of shells

 

2019-10-01

17:04:15

Exercise 40 - class

原文:https://www.cnblogs.com/petitherisson/p/11615102.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!