码迷,mamicode.com
首页 > 其他好文 > 详细

Exercise 40: Modules, Classes, And Objects

时间:2014-10-26 12:59:54      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   for   sp   div   on   log   

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()

 

Exercise 40: Modules, Classes, And Objects

标签:style   blog   color   ar   for   sp   div   on   log   

原文地址:http://www.cnblogs.com/hluo/p/4051799.html

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