Python 计算每个月天数

Python 3 教程 · 2019-02-12 15:28:11

以下代码通过导入 calendar 模块来计算每个月的天数:

实例(Python 3.0+)

#!/usr/bin/python3 # author by : www.codercto.com import calendar monthRange = calendar.monthrange(2016,9) print(monthRange)

执行以上代码输出结果为:

(3, 30)

输出的是一个元组,第一个元素是所查月份的第一天对应的是星期几(0-6),第二个元素是这个月的天数。以上实例输出的意思为 2016 年 9 月份的第一天是星期四,该月总共有 30 天。

点击查看所有 Python 3 教程 文章: https://www.codercto.com/courses/l/10.html

查看所有标签

High Performance Python

High Performance Python

Micha Gorelick、Ian Ozsvald / O'Reilly Media / 2014-9-10 / USD 39.99

If you're an experienced Python programmer, High Performance Python will guide you through the various routes of code optimization. You'll learn how to use smarter algorithms and leverage peripheral t......一起来看看 《High Performance Python》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换