网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

零基础学python日历calendar

时间:2024-10-25 04:10:05

1、首先导入calendar模块。

零基础学python日历calendar

2、# 月历(本质是字符串)a = calendar.month(2018, 2)print(a, type(a))运行结果如图

零基础学python日历calendar

3、# 年历(本质是字符串)b = calendar.calendar(2018)print(b, type(b))结果如图:

零基础学python日历calendar

4、# 判断200年是否是闰年c = calendar.isleap(200)print(c)结果如图:

零基础学python日历calendar

5、# 以周为单位的列表d = calendar.monthcalendar(2018, 2)print(d)结果如图:

零基础学python日历calendar

6、# 返回一个包含2个元素的元组# 元组里前面的元素代表,第一周少了多少天# 后面的元素代表本月有多少天e = calendar.monthrange(2018, 2)print(e)结果如图:

零基础学python日历calendar

7、 完整代码如下:

零基础学python日历calendar
© 2025 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com