零基础学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
猜你喜欢