As another example of a user-defined type, we’ll define a class called Time that records the time of day. The class definition looks like this:

Write a function print_time that takes a Time object and prints it in the form hour:minute:second.

Write a Boolean function after that takes two Time objects, t1 and t2, and returns true if t1 follows t2 chronologically and False otherwise.

class Time:
""" represents the time of day
attributes: hour, minute, second"""
def print_time(self):
print('%d:%d:%d' % (self.hour,self.minute,self.second))
def after(self,t):
if(self.hour < t.hour):
return False
elif(self.hour == t.hour):
if(self.minute < t.minute):
return False
elif(self.minute == t.minute):
if(self.second <= t.second):
return False
else: return True
return True time = Time()
time.hour = 11
time.minute = 59
time.second = 30
time1 = Time()
time1.hour = 11
time1.minute = 59
time1.second = 36
time2 = Time()
time2.hour = 11
time2.minute = 58
time2.second = 55

from Thinking in Python

Classes and functions的更多相关文章

  1. Think Python - Chapter 16 - Classes and functions

    16.1 TimeAs another example of a user-defined type, we’ll define a class called Time that records th ...

  2. C#软件设计——小话设计模式原则之:开闭原则OCP

    前言:这篇继续来看看开闭原则.废话少说,直接入正题. 软件设计原则系列文章索引 C#软件设计——小话设计模式原则之:依赖倒置原则DIP C#软件设计——小话设计模式原则之:单一职责原则SRP C#软件 ...

  3. Python演讲笔记1

    参考: 1. The Clean Architecture in Python (Brandon Rhodes) 2. Python Best Practice Patterns (Vladimir ...

  4. 开放封闭原则(Open Closed Principle)

    在面向对象的设计中有很多流行的思想,比如说 "所有的成员变量都应该设置为私有(Private)","要避免使用全局变量(Global Variables)",& ...

  5. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

  6. [python实现设计模式]-3.简单工厂模式-触宝开放平台

    预备知识: 开放封闭原则(Open-Closed Principle OCP) Software entities(classes,modules,functions etc) should open ...

  7. React学习笔记---项目构建

    简介 ReactJs由于有FB的支持,得到了社区的极大关注,同时由于ReactJs只希望专一的做好View层次上的工作,所以本身并没有涉及很多周边工具. 今天要介绍一款工具,同时包含一个构建项目模板的 ...

  8. 我们的动机(Our motivation)

    我们的动机(Our motivation) There are many PHP frameworks nowadays, but none of them is like Phalcon (Real ...

  9. iOS.OpenSource.AllInOne

    Open Source Project for iOS 所有和iOS相关的Open Source Project的汇总. 功能点 开源项目   iOS Gallery RMGallery https: ...

随机推荐

  1. 【动态树问题】LCT学习笔记

    我居然还不会LCT QAQ真是太弱了 必须学LCT QAQ ------------------线割分是我www------------ LinkCut-Tree是基于Splay(由于Splay能够非 ...

  2. 葡萄城公布新版ActiveReports 9报表控件和报表server

    2014年11月10日---葡萄城宣布正式公布ActiveReports9,包含了三种报表模型:RDL报表.页面报表.区域报表.对于ActiveReports中的这个最新版本号中,我们专注于提高产品的 ...

  3. nmq 提交到 npm

    安装npm install nmq 源码:https://github.com/ronwe/nmq 此版本提供 pub/sub , 优化 pull

  4. Qt 3D教程(三)实现对模型材质參数的控制

    Qt 3D教程(三)实现对模型材质參数的控制 蒋彩阳原创文章,首发地址:http://blog.csdn.net/gamesdev/article/details/47131841.欢迎同行前来探讨. ...

  5. YII 数据库查询

    $userModel = User::Model(); $userModel->count(); $userModel->count($condition); $userModel-> ...

  6. Android 6.0 开发人员对系统权限的使用与练习(Permissions Best Practices)

    Permissions Best Practices 在安装的过程中,用户非常easy忽略权限请求. 假设一个用户相应用感觉沮丧或者操心泄漏个人信息,那么这些用户就会不用他或者卸载它. 怎样规避这个问 ...

  7. C++之易混淆知识点三---算法分析

    最近复习算法,感到有一丝丝忘记的困惑,赶紧记下来... 一.分治法 分治法的思想就是“分而治之”,很明显就是将规模比较庞大.复杂的问题进行分治,然后得到多个小模块,最好这些小模块之间是独立的,如果这些 ...

  8. 【原创】websphere部署war包报错

    应用程序在Tomcat上运行一切正常,但在websphere上部署时报以下错误:错误 500 处理请求时发生一个错误: /admin/upload.do 消息: WEB-INF/web.xml 详细错 ...

  9. swift语言点评十一-Methods

    Assigning to self Within a Mutating Method Mutating methods can assign an entirely new instance to t ...

  10. 优动漫PAINT-超简单灌木教程

    超简单灌木教程~零基础神马的都能神还原哦! 优动漫PAINT下载:http://wm.makeding.com/iclk/?zoneid=18597 想要Get到更多有关优动漫的信息包括软件下载,可关 ...