零基础学python日历calendar

2025-07-09 17:13:23

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
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢