python学习笔记(15)object,类,组的学习 今天碰到难题了

1、今天碰到好几个难点,面对对象编程的概念,操作,理解,这几天要好好专研下。


2、object传递参数这个理解了好久


class Song(object):#object用来传递参数的

    
    def __init__(self, lyrics):
        #__init__下划线是两横,
        #__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"])


print(happy_bday)
print(bulls_on_parade)


happy_bday.sing_me_a_song()


bulls_on_parade.sing_me_a_song()

你可能感兴趣的:(python学习笔记(15)object,类,组的学习 今天碰到难题了)