Skip to Content
Python语言及其应用(第2版)
book

Python语言及其应用(第2版)

by Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from Python语言及其应用(第2版)
212
13
13.1
闰年
闰年是时间特殊的褶皱
1
。你也许知道每
4
年会出现一个闰年(夏季奥运会和美国总统选举
也是每
4
年一次)
。你知道每
100
年不是闰年,但每
400
年是闰年吗?下面是测试各种年
份是否为闰年的代码。
>>> import calendar
>>> calendar.isleap(1900)
False
>>> calendar.isleap(1996)
True
>>> calendar.isleap(1999)
False
>>> calendar.isleap(2000)
True
>>> calendar.isleap(2002)
False
>>> calendar.isleap(2004)
True
好奇的读者可以了解以下内容。
一年有
365.242 196
天(在围绕太阳旋转一圈后,地球在地轴上大约转了
1/4
)。
4
年会增加
1
天。现在,平均一年有
365.242 196–0.25=364.992 196
天。
100
年会减少
1
天。现在,平均一年有
364.992 196+0.01=365.002 196
天。
400
年会增加
1
天。现在,平均一年有
365.002 196–0.002 5=364.999 696
天。
差不多了!就不谈闰秒了。
13.2
datetime
模块
标准模块
datetime
可用于处理日期和时间(这应该不意外)。该模块定义了
4
个主要的对
象类,每个对象类都包含多种方法:
date
处理年、月和日;
time
处理时、分、秒和微秒;
• ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham
Python技术基础视频教程

Python技术基础视频教程

保罗·J·戴特尔
Python面向对象编程指南

Python面向对象编程指南

Posts & Telecom Press, Steven F. Lott

Publisher Resources

ISBN: 9787115586223