Exercise 40 - class

Posted petitherisson

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 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的主要内容,如果未能解决你的问题,请参考以下文章

Exercise 42 - class and instantiate

Python基础lpthw - Exercise 40 模块类和对象

Week 5: Object Oriented Programming 9. Classes and Inheritance Exercise: int set

Wordpress阻止访问wp admin€“wpsnipp.com网站你博客的Wordpress代码片段

滚动经过片段时,Angular 10会获得路由器活动片段吗?

如何在每个导航选项卡的片段内创建 2 个片段