classSong(object):def__init__(self,lyrics):
self.lyrics = lyrics
defsing_me_a_song(self):for line in self.lyrics:print(line)# 对象1,列表作为lyrics需要的参数传入
happy_bday = Song(["Happy birthday to you","I don't want to get sued","So I'll stop right there"])# 对象2
bulls_on_parade = Song(["They rally around the family","With pockets full of shells"])# 对象1调用类中的方法
happy_bday.sing_me_a_song()# 对象2调用类中的方法
bulls_on_parade.sing_me_a_song()
PS C:\Users\h>
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
PS C:\Users\h>
class Song(object): def __init__(self,lyrics): self.lyrics = lyrics def sing_me_a_song(self): for line in self.lyrics: print(line)# 对象1,列表作为lyrics需要的参数传入happy_bday = Song(["Happy birthday to you",