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. LeetCode211:Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  2. Picking up Jewels

    Picking up Jewels There is a maze that has one entrance and one exit.  Jewels are placed in passages ...

  3. Hibernate中session回话的get方法和load方法的区别

    1.报错方式不同: 前提:获取的数据不存在 get方法会报异常:空指针异常 load方法会报异常:对象为找到异常,给定值没有行存在. 2.load方法 这种方式总是会返回一个代理而不是真正得去查询数据 ...

  4. ThinkPHP5.0最最最最最简单实例

    ThinkPHP5.0最最最最最简单实例 一.效果图 二.操作步骤 1.用mysql数据库建立数据库 2.按照ThinkPHP官网的指示装好ThinkPHP5.0 tp5里面的目录结构如下: 3.配置 ...

  5. nyoj--214--单调递增子序列(二)(二分查找+LIS)

    单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 给定一整型数列{a1,a2...,an}(0<n<=100000),找出单调递增最长子序 ...

  6. pgsql数据库备份还原记

    今天又搞了一个pgsql 的备份还原,差一点没有成功,以前总是想当然的用,没认真想背后的东西,也没对过程中的疑问做记录,所以后面也没什么印象,常见常新,这次既然又遇到就总结一下. 之前操作pgsql数 ...

  7. [JZOJ 5894] [NOIP2018模拟10.5] 同余方程 解题报告(容斥)

    题目链接: http://172.16.0.132/senior/#contest/show/2523/0 题目: 题解:(部分内容来自https://blog.csdn.net/gmh77/arti ...

  8. select … into outfile 备份恢复(load data)以及mysqldump时间对比

    select … into outfile 'path' 备份 此种方式恢复速度非常快,比insert的插入速度要快的多,他跟有备份功能丰富的mysqldump不同的是,他只能备份表中的数据,并不能包 ...

  9. Android tablayout增加选择tab 的事件.

    tablayout在点击或者滑动的时候会触发监听事件  , 当你调用这个方法的时候 会触发事件 mTablayout.addOnTabSelectedListener(new TabLayout.On ...

  10. Oracle查询当前用户下的所有表及sqlplus 设置 列宽

    如果oracle服务器中装有多个数据库实例,则在用户名处输入:用户名/密码@数据库名称.如果数据库服务器不在本机上,还需要加上数据库服务器的地址:用户名/密码@IP地址/数据库名称. [oracle@ ...