python Calendar日历模块函数介绍
1、calendar.calendar(year,w=2,l=1,c=6):返回year年年历
返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。
2、calendar.firstweekday( ):返回当前每周起始日期的设置。
默认情况下,首次载入 calendar 模块时返回 0,即星期一。
3、calendar.setfirstweekday(weekday):设置每周的起始日期码
import calendar
c0 = calendar.firstweekday() # 输出:0
calendar.setfirstweekday(1) # 设置周一为1
c1 = calendar.firstweekday() # 输出:1
4、 calendar.isleap(year) :闰年返回 True,否则为 False。
print(calendar.isleap(2022)) # False
5、 calendar.leapdays(y1,y2) :返回在Y1,Y2两年之间的闰年总数
print(calendar.leapdays(2000,2022)) # 6
6、calendar.month(year,month,w=2,l=1):返回year年month月日历
返回一个多行字符串格式的year年month月日历,两行标题,一周一行。每日宽度间隔为w字符。每行的长度为7* w+6。l是每星期的行数。
print(calendar.month(2022, 9, w=2, l=1))
输出:
7、 calendar.monthcalendar(year,month)
返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。
print(calendar.monthcalendar(2022,9))
输出:
[[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, 0, 0]]
8、calendar.monthrange(year,month)—返回(month月第一天是星期几,month月天数)
返回的是一个元组数据(两个整数)。
第一个整数:代表本月起始星期数(0:星期一 … 6:星期天)
第二个整数:代表本月最后一天的日期数,即该月天数
print(calendar.month(2022, 9))
print(calendar.monthrange(2022, 9)) # (3, 30)输出:September 2022
Mo Tu We Th Fr Sa Su1 2 3 45 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(3, 30)
9、calendar.monthlen( year , month ):返回month 月天数
print(calendar.monthlen(2022,9)) # 30
10、calendar.weekday(year,month,day):返回给定日期的日期码。
0(星期一)到6(星期日)。
print(calendar.month(2022, 9))
# 输出2022-9-30号对应的日期码
print(calendar.weekday(2022,9,30)) # 4 输出:September 2022
Mo Tu We Th Fr Sa Su1 2 3 45 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 304
11、calendar.prevmonth(year, month):返回month的上一个月year, month-1)
12、calendar.nextmonth(year, month):返回month的下一个月(year, month+1)
print(calendar.prevmonth(2022, 1)) # (2021, 12)
print(calendar.prevmonth(2022, 4)) # (2022, 3)
print(calendar.nextmonth(2022, 12)) # (2023, 1)
print(calendar.nextmonth(2022, 9)) # (2022, 10)
python Calendar日历模块函数介绍相关推荐
- Python calendar日历模块的常用方法
Python calendar日历模块的常用方法 如果您想知道某一天是星期几,某个月有多少个周末...那么,日历对您来说非常方便.您的办公桌有制作精美的日历,手机里也有日历,电脑里也有日历,随手可得. ...
- python日历模块提示没有属性月_Python calendar日历模块的说明
calendar(日历)模块,默认每周第一天是星期一,最后一天是星期天. 函数及描述 1. calendar.calendar(year, w=2, l=1, c=6, m=3) 返回一个多行字符串格 ...
- python跨函数调用变量_对python中不同模块(函数、类、变量)的调用详解
首先,先介绍两种引入模块的方法. 法一:将整个文件引入 import 文件名 文件名.函数名( ) / 文件名.类名 通过这个方法可以运行另外一个文件里的函数 法二:只引入某个文件中一个类/函数/变量 ...
- 五. python的日历模块
一 .日历 import calendar# 日历模块# 使用# 返回指定某年某月的日历 print(calendar.month(2017,7))# July 2017 # Mo Tu We Th ...
- python3之calendar日历模块
calendar日历模块 import calendar calendar.calendar(theyear, w=2, l=1, c=6, m=3) theyear:年份 w:每一小格的宽度 l:每 ...
- Python中numpy.power()函数介绍
Python中numpy.power()函数介绍 power(x, y) 函数,计算 x 的 y 次方. 示例: x 和 y 为单个数字: import numpy as npprint(np.pow ...
- Python编程语言学习:python语言中快速查询python自带模块函数的用法及其属性方法、如何查询某个函数关键词的用法、输出一个类或者实例化对象的所有属性和方法名之详细攻略
Python编程语言学习:python语言中快速查询python自带模块&函数的用法及其属性方法.如何查询某个函数&关键词的用法.输出一个类或者实例化对象的所有属性和方法名之详细攻略 ...
- python的常用函数模块_(5)Python的常用模块函数
python 的常用系统函数,random模块函数,time模块函数和calendar模块函数. 1 random模块函数. 随机数种字,使用seed(x)函数可以设置随机数生成器的种子,通常在调用其 ...
- python中math模块函数_Python常用的一些内建函数和math模块函数
一:Python内建函数 1 #abs取绝对值 2 num = -10 3 print(abs(num))4 5 #max 求最大值 6 print(max(6, 9, 2, 12, 8))7 8 # ...
- Python中各个模块的介绍和使用
北京 | 高性能计算之GPU CUDA课程11月24-26日3天密集学习 快速带你晋级阅读全文> 作者,许胜利,Python开发工程师,任职于上海某财富管理有限公司. 在Python中有一个概念 ...
最新文章
- MySQL数据库:常见经典SQL语句
- Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
- [Oracle运维工程师手记] 如何从trace 文件,判断是否执行了并行
- zookeeper客户端练习(idea-Junit测试)
- 三、华为鸿蒙HarmonyOS应用开发HUAWEI DevEco Studio实现页面跳转
- C# LINQ to XML
- 获取.propertys文件获取文件内容
- 学习计算机如何有一个质的飞越?
- java csv api_CSVAPIforJava
- cad填充图案乱理石_cad填充图案(cad中如何进行图案填充?)
- CRNN——卷积循环神经网络结构
- HTML特效文字代码大全
- reviewboard使用 与原理
- python编程竞赛规则_第十一届蓝桥杯Python规则及样题
- gitee仓库人员上限如何一键删人
- PHP7.1 mcrypt_module_open() is deprecated
- 喝酒神器小程序源码+全新带特效/多种游戏/支持流量主
- html 如何设置选择图片,html中如何设置默认图片?
- 2019华师在线计算机,华师计算机基础客观作业2019.pdf
- Java流程控制之do....while 循环的详解,看完你就会