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. 【leetcode】801. Minimum Swaps To Make Sequences Increasing

    题目如下: We have two integer sequences A and B of the same non-zero length. We are allowed to swap elem ...

  2. Word:图片压缩

    造冰箱的大熊猫,本文适用于Microsoft Word 2007@cnblogs 2018/12/1 图片插入Word文档后,可以通过“裁剪”功能只显示图片的部分区域.虽然文档中显示的图片区域变小了, ...

  3. 【杂题】[AGC034D] Manhattan Max Matching【费用流】

    Description 有一个无限大的平面,有2N个位置上面有若干个球(可能重复),其中N个位置是红球,N个位置是蓝球,红球与蓝球的总数均为S. 给出2N个位置和上面的球数,现要将红球与蓝球完美匹配, ...

  4. gwyh 测试赛 验题人 - 题解 (非std做法)

    测试赛 - ljc20020730 解题报告 标签(空格分隔): solution Task A Tiat's easy question 首先,判断图中是否存在长度为奇数的环等价于判断图是否为二分图 ...

  5. POJ1703--Find them, Catch them(种类并查集)

    Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 32909Accepted: 10158 Description The polic ...

  6. 使用keil生成bin文件

      相关文件  下载http://pan.baidu.com/share/link?shareid=478269&uk=1107426113 使用kei自带的工具的话是 打开Options f ...

  7. 工具类-ApplicationContextUtil

    package com.zhouyy.netBank.util; import org.springframework.beans.BeansException; import org.springf ...

  8. Spring-data-redis 第一天

    1.Redis 这就不必哆嗦了,Redis 支持丰富的数据类型,String ,List,Sets ,Sorted Sets,Hashes,这就可以看出Java 操作Redis就要针对各种类型都有自己 ...

  9. easyui tree 点击state=closed节点,每次重新加载数据

    http://blog.csdn.net/lovejavaloveworld/article/details/30052305 树控件读取URL.子节点的加载依赖于父节点的状态.当展开一个封闭的节点, ...

  10. spring boot V部落 V人事项目

    公司倒闭 1 年多了,而我在公司倒闭时候做的开源项目,最近却上了 GitHub Trending,看着这个数据,真是不胜唏嘘. 缘起 2017 年 11 月份的时候,松哥所在的公司因为经营不善要关门了 ...