zoukankan      html  css  js  c++  java
  • 一个有意义的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!
  • 相关阅读:
    模块3 re + 正则表达式
    模块2
    模块1
    super
    MRO,C3算法
    日志,固定格式
    异常处理,MD5
    类的约束
    反射
    异常处理MR5
  • 原文地址:https://www.cnblogs.com/jaysonguan/p/6758998.html
Copyright © 2011-2022 走看看