calendar

1. calendar.calendar(year, w, l, c, m)

  • Returns a year's calendar as a multi-line string.
>>> import calendar
>>> cal = calendar.calendar(2019)
>>> print(type(cal))
<class 'str'>
>>> print(cal)
2019 January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 1 2 3 1 2 3
7 8 9 10 11 12 13 4 5 6 7 8 9 10 4 5 6 7 8 9 10
14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17
21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24
28 29 30 31 25 26 27 28 25 26 27 28 29 30 31 April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7 1 2 3 4 5 1 2
8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9
15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16
22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23
29 30 27 28 29 30 31 24 25 26 27 28 29 30 July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7 1 2 3 4 1
8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8
15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15
22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22
29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29
30 October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 1 2 3 1
7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8
14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15
21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22
28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29
30 31
  • calendar.calendar(year, w=2, l=1, c=6, m=3)

    • 返回一个多行字符串格式的 year 年年历
    • w 为日期列宽度的字符数(因为日子有单数、双数,所以一般为 2)
    • l 为每周行数(若设为 2,就是头一行显示字符,下一行空着;数字增大,下方空行随之增多)
    • c 为月份之间的空格数
    • m 为每行显示的月份数

2. calendar.prcal(year, w, l, c, m)

  • Print a year's calendar.
  • w, l, c, m 的用法同 calendar.calendar(year, w, l, c, m)
  • calendar.prcalcalendar.calendar 的参数默认值有所不同
    • calendar.prcal(year, w=0, l=0, c=6, m=3)
    • calendar.calendar(year, w=2, l=1, c=6, m=3)
# 下方两句结果相同
>>> print(calendar.calendar(2019))
...
>>> calendar.prcal(2019)
...

3. calendar.month(year, month, w, l)

  • Return a month's calendar string (multi-line).
  • w, l 的用法同 calendar.calendar(year, w, l, c, m)
>>> m12 = calendar.month(2019, 12)
>>> print(m12)
December 2019
Mo Tu We Th Fr Sa Su
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

4. calendar.prmonth(year, month, w, l)

  • Print a month's calendar.
  • w, l 的用法同 calendar.calendar(year, w, l, c, m)
  • calendar.prmonthcalendar.calendar 的参数默认值有所不同
    • calendar.prmonth(year, month, w=0, l=0)
    • calendar.calendar(year, w=2, l=1, c=6, m=3)
# 下方两句结果相同
>>> print(calendar.month(2019, 12))
...
>>> calendar.prmonth(2019, 12)
...

5. calendar.isleap(year)

  • Return True for leap years, False for non-leap years.
>>> calendar.isleap(2000)
True
>>> calendar.isleap(2019)
False

6. calendar.leapdays(y1, y2)

  • Return number of leap years in range [y1, y2).
  • Assume y1 <= y2.
>>> calendar.leapdays(2000, 2019)
5
>>> calendar.leapdays(2019, 2000)
-5

7. calendar.monthcalendar(year, month)

  • Return a matrix representing a month's calendar.
  • Each row represents a week; days outside this month are zero.
>>> m12 = calendar.monthcalendar(2019, 12)
>>> type(m12)
<class 'list'>
>>> m12
[[0, 0, 0, 0, 0, 0, 1], [2, 3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22], [23, 24, 25, 26, 27, 28, 29], [30, 31, 0, 0, 0, 0, 0]]

8. calendar.monthrange(year, month)

  • Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for year, month.
>>> calendar.monthrange(2019, 12)
(6, 31)

9. calendar.weekday(year, month, day)

  • Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31).
>>> calendar.weekday(2019, 12, 1)
6

[Python3] 026 常用模块 calendar的更多相关文章

  1. 09 . Python3之常用模块

    模块的定义与分类 模块是什么? 一个函数封装一个功能,你使用的软件可能就是由n多个函数组成的(先备考虑面向对象).比如抖音这个软件,不可能将所有程序都写入一个文件,所以咱们应该将文件划分,这样其组织结 ...

  2. 【Python3之常用模块】

    一.time 1.三种表达方式 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.命令如下 ...

  3. [Python3] 032 常用模块 random

    目录 random 1. random.random() 2. random.choice() 3. random.shuffle() 4. random.randint() 5. random.ra ...

  4. [Python3] 031 常用模块 shutil & zipfile

    目录 shutil 1. shutil.copy() 2. shutil.copy2() 3. shutil.copyfile() 4. shutil.move() 5. 归档 5.1 shutil. ...

  5. [Python3] 030 常用模块 os

    目录 os 1. os.getcwd() 2. os.chdir() 3. os.listdir() 4. os.makedir() 5. os.system() 6. os.getenv() 7. ...

  6. [Python3] 028 常用模块 datetime

    目录 datetime 1. datetime.date 2. datetime.time 3. datetime.datetime 4. datetime.timedelta 补充 datetime ...

  7. [Python3] 029 常用模块 timeit

    目录 timeit 直接举例 1. 测量生成列表的时间 2. 测量函数运行时间(一) 3. 测量函数运行时间(二) timeit 直接举例 必要的导入 import timeit 1. 测量生成列表的 ...

  8. [Python3] 027 常用模块 time

    目录 time 1. 时间戳 2. UTC 时间 3. 夏令时 4. 时间元组 5. 举例 5.1 例子1 例子2 例子3 例子4 例子5 例子6 例子7 time 1. 时间戳 一个时间表示,根据不 ...

  9. python3 常用模块详解

    这里是python3的一些常用模块的用法详解,大家可以在这里找到它们. Python3 循环语句 python中模块sys与os的一些常用方法 Python3字符串 详解 Python3之时间模块详述 ...

随机推荐

  1. CentOS7安装MySQL报错Failed to start mysqld.service: Unit not found解决办法

    1 ~]# systemctl start mysql.service 要启动MySQL数据库是却是这样的提示 1 ~]# Failed to start mysqld.service: Unit n ...

  2. AOP xml 配置

    applicationContext.xml <!--切面Bean--> <bean id ="aspectbean" class='"con.soft ...

  3. JavaScript 正则表达式——预定义类,边界,量词,贪婪模式,非贪婪模式,分组,前瞻

    ㈠预定义类    示例:匹配一个ab+数字+任意字符的字符串:ab\d.   ㈡边界 正则表达式常用的边界匹配字符   ⑴示例1:第一个是没写单词边界             第二个是加上字符边界的效 ...

  4. 数据库范式以及ER图

    数据库范式包括第一.第二.第三以及BCNF范式,关于范式的探讨,博主在知乎上看见了一篇很不错的文章,分享文中,这边就不再做阐述.地址:https://www.zhihu.com/question/24 ...

  5. FFT用于高效大数乘法(当模板用)

    转载来源:https://blog.csdn.net/zj_whu/article/details/72954766 #include <cstdio> #include <cmat ...

  6. note: Spanner: Google’s Globally-Distributed Database

    1. Abstract & introduction ref:http://static.googleusercontent.com/media/research.google.com/zh- ...

  7. oracle delete 数据恢复

    /*1.FLASHBACK QUERY*/ --闪回到15分钟前 select *  from orders  as of timestamp (systimestamp - interval ''1 ...

  8. Vimdiff 使用

    what is vimdiff 在类nuix平台,我们希望对文件之间的差异之间快速定位,希望能够很容易的进行文件合并……. 可以使用Vim提供的diff模式,通常称作vimdiff,就是这样一个能满足 ...

  9. [SQL分页语句的三种方式]

    我们在开发的过程经常会用到数据分页,在网上也可以搜到大量的分页插件.这是在端上控制的;有的是在SQL语句实现分页,这是在数据源上 实现分页的; 今天,我就在总结一下我经常用到的SQL语句分页! 第一种 ...

  10. Android Studio设置国内镜像代理

    点击主面板右下角的Configure –> settings –> Appearance & Behavior –> System Settings –> HTTP P ...