言成说 - 对象
type: channel
link: https://www.elecdiy.com/tag/%E5%AF%B9%E8%B1%A1/
items: ex40 模块、类、对象

ex40 模块、类、对象
type: item
date: 2021-04-14T22:13:16+08:00
description: 程序代码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() 输出结果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