首页 > 代码库 > 一个有意义的Day类
一个有意义的Day类
早晨去单位的路上听到电台里在说“Everyday is a new chance to change your life”,正好最近在学Python类的使用方法,于是我编了一个关于Day的类,以供参考。
1 class Day(object): 2 3 def __init__(self, when): 4 self.when = when 5 6 def result(self): 7 if self.when == "today": 8 print self.when.title(),"is in my hands!" 9 elif self.when == "tomorrow": 10 print self.when.title(),"is a new chance to change your life!" 11 elif self.when == "yesterday": 12 print self.when.title(),"comes true." 13 else: 14 print "It‘s a good day!" 15 16 my_day = Day("today") 17 your_day = Day("tomorrow") 18 19 my_day.result() 20 your_day.result()
当然,结果是:
Today is in my hands!
Tomorrow is a new chance to change your life!
一个有意义的Day类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。