码迷,mamicode.com
首页 > 编程语言 > 详细

笨方法学Python——习题40

时间:2017-11-25 17:23:20      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:编程   get   例子   family   lin   app   关于   color   you   

之前例子讲过关于字典、列表、字符串、元组,按书中所述,其实这些已经足够写一些代码,但Python属于面向对象的编程语言,本节所讲的类,是必须要掌握的,虽然现在有些懵逼

 1 class Song(object):
 2 
 3     def __init__(self, lyrics):
 4         self.lyrics = lyrics
 5 
 6     def sing_me_a_song(self):
 7         for line in self.lyrics:
 8             print line
 9 
10 happy_bday = Song(["Happy birthday to you",
11                     "I don‘t want to get sued",
12                     "So I‘ll stop right there"])
13 
14 bulls_on_parade = Song(["They rally around the family",
15                         "With pockets full of shells"])
16 
17 happy_bday.sing_me_a_song()
18 
19 bulls_on_parade.sing_me_a_song()

 

笨方法学Python——习题40

标签:编程   get   例子   family   lin   app   关于   color   you   

原文地址:http://www.cnblogs.com/hejianlong/p/7895502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!