[Python3] 026 常用模块 calendar
- calendar
- 1. calendar.calendar(year, w, l, c, m)
- 2. calendar.prcal(year, w, l, c, m)
- 3. calendar.month(year, month, w, l)
- 4. calendar.prmonth(year, month, w, l)
- 5. calendar.isleap(year)
- 6. calendar.leapdays(y1, y2)
- 7. calendar.monthcalendar(year, month)
- 8. calendar.monthrange(year, month)
- 9. calendar.weekday(year, month, day)
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.prcal 与 calendar.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.prmonth 与 calendar.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的更多相关文章
- 09 . Python3之常用模块
模块的定义与分类 模块是什么? 一个函数封装一个功能,你使用的软件可能就是由n多个函数组成的(先备考虑面向对象).比如抖音这个软件,不可能将所有程序都写入一个文件,所以咱们应该将文件划分,这样其组织结 ...
- 【Python3之常用模块】
一.time 1.三种表达方式 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.命令如下 ...
- [Python3] 032 常用模块 random
目录 random 1. random.random() 2. random.choice() 3. random.shuffle() 4. random.randint() 5. random.ra ...
- [Python3] 031 常用模块 shutil & zipfile
目录 shutil 1. shutil.copy() 2. shutil.copy2() 3. shutil.copyfile() 4. shutil.move() 5. 归档 5.1 shutil. ...
- [Python3] 030 常用模块 os
目录 os 1. os.getcwd() 2. os.chdir() 3. os.listdir() 4. os.makedir() 5. os.system() 6. os.getenv() 7. ...
- [Python3] 028 常用模块 datetime
目录 datetime 1. datetime.date 2. datetime.time 3. datetime.datetime 4. datetime.timedelta 补充 datetime ...
- [Python3] 029 常用模块 timeit
目录 timeit 直接举例 1. 测量生成列表的时间 2. 测量函数运行时间(一) 3. 测量函数运行时间(二) timeit 直接举例 必要的导入 import timeit 1. 测量生成列表的 ...
- [Python3] 027 常用模块 time
目录 time 1. 时间戳 2. UTC 时间 3. 夏令时 4. 时间元组 5. 举例 5.1 例子1 例子2 例子3 例子4 例子5 例子6 例子7 time 1. 时间戳 一个时间表示,根据不 ...
- python3 常用模块详解
这里是python3的一些常用模块的用法详解,大家可以在这里找到它们. Python3 循环语句 python中模块sys与os的一些常用方法 Python3字符串 详解 Python3之时间模块详述 ...
随机推荐
- LINUX学习之二磁盘篇
1.Linux系统中,每个设备都被当成一个文件来对待.文件系统的最小单位是区块(Block) 设备 设备在Linux中的文件名 IDE硬盘 /dev/hd[a-d] SCSI/SATA/USB硬盘 / ...
- SQL SERVER 2008 设置字段默认值为当前时间
在某些情况下需要对某条记录添加上时间戳,比如用户注册,需要记录用户的注册时间,在SQL SERVER 2008中可以通过 1. 添加新字段 2. 数据类型设置为smalldatetime 3. 默认值 ...
- Linux系统上java调用C++ so库文件
PART1: java中使用jna替代jni调用c++/c生成的 dll/so库文件需要做的事项 1.引入JNA依赖或者直接下载JNAjar包 <!-- http ...
- Here is a test page for my new blog in cnblogs
Tell me if I can use Fomula like LaTeX $$\sum\limits_{i = 1}^{n}a_i$$
- vue 项目, 通知子组件更新,父组件中每次点击按钮重新加载子组件,(重新生成dom 元素)
vue是组件化开发的项目,很多情况下会把公共组件提取出来,来减少代码量,提高开发效率,和以后更好的可维护性.很多情况下,父组件中都会引用子组件这种情况.通过给在父组件中引用的子组件标签上添加属性,来渲 ...
- [深度学习] pytorch利用Datasets和DataLoader读取数据
本文简单描述如果自定义dataset,代码并未经过测试(只是说明思路),为半伪代码.所有逻辑需按自己需求另外实现: 一.分析DataLoader train_loader = DataLoader( ...
- HTML+CSS知识总结1
一.浏览器页面页面由结构层(html)表现层(css)行为层(js)组成 二.DOCTYPE作用是用来告知浏览器以何种模式渲染文档. 三.严格模式是指浏览器按照W3C标准解析代码,混杂模式又称怪异模式 ...
- WebView内置方案主要是通过重写WebChromeClient 来实现的,如下面的代码所示。
基本思想也很简单:通过WebChromeClient的方法以startActivityForResult的方式打开系统的文件选择器,选择文件后在onActivityResult中将结果回传给Webvi ...
- DeepFaceLab参数详解之FPS与Image format
DeepFaceLab参数详解之FPS与Image format , 本文讲解两个非常简单的参数,也是大家玩这个软件最先接触到的.参数虽然非常的简单,但是非常有用,适当调整可以为你节省大量硬盘空间,大 ...
- SVN 清理失败解决方案
SVN有时因各种不明原因导致清理失败,可以采取如下解决办法进行处理: 方法一: 删除根目录下隐藏文件夹“.svn” 然后在根目录文件夹 外面的空白处 检出.比如你项目文件夹名为“D:/source” ...