monthcalendar

Python calendar.monthcalendar()方法 (Python calendar.monthcalendar() Method)

monthcalendar() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and returns a matrix representing the given month's calendar. Each row in the matrix represents a full week, and the days outside of the month are represented by zeros.

monthcalendar()方法是Python中日历模块的内置方法。 它适用于简单的文本日历,并返回代表给定月份日历的矩阵。 矩阵中的每一行代表一整周,月份之外的天数由零表示。

Module:

模块:

    import calendar

Syntax:

句法:

    monthcalendar(year, month)

Parameter(s):

参数:

  • year: It is a required parameter, which represents the year of the calendar.

    year :这是必填参数,代表日历的年份。

  • month: It is a required parameter, which represents the month of the calendar.

    month :这是必填参数,代表日历的月份。

Return value:

返回值:

The return type of this method is <class 'list'> (a matrix), which represents the calendar of the given month of the given year.

此方法的返回类型为<class'list'> (矩阵),它表示给定年份的给定月份的日历。

Example:

例:

# Python program to illustrate the
# use of monthcalendar() method
# importing calendar module
import calendar
year = 2020
month = 4
x = calendar.monthcalendar(year, month)
print("Calendar of April 2020 as a matrix")
for i in range(len(x)):
print(x[i])
print()
# Prints the calendar of the given month
# where 0 values are days out of that month
year = 1997
month = 1
a, b= calendar.monthrange(year, month)
x = calendar.monthcalendar(year, month)
print("Weekday starts from:", a)
print("Calendar of January 1997 as a matrix")
for i in range(len(x)):
print(x[i])
print()
# You can see the month starts from x[0][a]
year = 2000
month = 5
x = calendar.monthcalendar(year, month)
print("calendar of May 2020 as a matrix")
for i in range(len(x)):
print(x[i])
print()
calendar.setfirstweekday(6)
x = calendar.monthcalendar(year, month)
# Here column number 0  represents Sunday and so on
print("Calendar of May 2020 with first column representing Sunday")
for i in range(len(x)):
print(x[i])

Output

输出量

Calendar of April 2020 as a matrix
[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, 0]
Weekday starts from: 2
Calendar of January 1997 as a matrix
[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]
calendar of May 2020 as a matrix
[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]
Calendar of May 2020 with first column representing Sunday
[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]

翻译自: https://www.includehelp.com/python/calendar-monthcalendar-method-with-example.aspx

monthcalendar

monthcalendar_Python日历模块| 带有示例的monthcalendar()方法相关推荐

  1. python中weekday_[转载] Python日历模块| 使用示例的weekday()方法

    参考链接: Python中的日历函数 2(monthrange(),prcal(),weekday()-) Python calendar.weekday()方法 (Python calendar.w ...

  2. [转载] Python日历模块| 使用示例的weekday()方法

    参考链接: Python中的日历函数 2(monthrange(),prcal(),weekday()-) Python calendar.weekday()方法 (Python calendar.w ...

  3. Python日历模块| 使用示例的weekday()方法

    Python calendar.weekday()方法 (Python calendar.weekday() Method) weekday() method is an inbuilt method ...

  4. python日历模块_Python日历模块| firstweekday()方法与示例

    python日历模块 Python calendar.firstweekday()方法 (Python calendar.firstweekday() Method) firstweekday() m ...

  5. python日历模块_Python日历模块| prmonth()方法与示例

    python日历模块 Python calendar.prmonth()方法 (Python calendar.prmonth() Method) prmonth() method is an inb ...

  6. python日历模块_Python日历模块| setfirstweekday()方法与示例

    python日历模块 Python calendar.setfirstweekday()方法 (Python calendar.setfirstweekday() Method) setfirstwe ...

  7. Python日历模块| weekheader()方法与示例

    Python calendar.weekheader()方法 (Python calendar.weekheader() Method) weekheader() method is an inbui ...

  8. python日历节日表_python日历模块_Python日历模块| calendar()方法与示例

    python日历模块 Python calendar.calendar()方法 (Python calendar.calendar() Method) calendar() method is an ...

  9. Python HTMLCalendar类| 带有示例的formatyearpage()方法

    Python HTMLCalendar.formatyearpage()方法 (Python HTMLCalendar.formatyearpage() Method) formatyearpage( ...

  10. python 示例_带有示例的Python File write()方法

    python 示例 文件write()方法 (File write() Method) write() method is an inbuilt method in Python, it is use ...

最新文章

  1. sql server where 条件 区分大小写查询
  2. 投票选举c语言程序,C语言元旦礼物:经典入门问题分析——选举投票
  3. 遍历HashMap的四种方法
  4. 物理数据模型(PDM)-概念数据模型 (CDM)-面向对象模型 (OOM):适用于已经设计好数据库表结构了。...
  5. 鸿蒙-秒级网址在线监控V1.4工具-可多开
  6. UVa 1588 换抵挡装置
  7. arduino蜂鸣器音乐代码青花瓷_教你用 Arduino 制造简易金属探测器
  8. Oracle 数字与空值的排序问题
  9. EMC与电阻、电容和电感的关系
  10. 什么是路由守卫?有什么用?
  11. 博文翻译:Tackling the Cold Start Problem in Recommender Systems
  12. POE交换机应该要选择网线?POE交换机选择网线要点
  13. 记事本如何写代码并运行代码
  14. 【Web前端笔记-基础】第八课·初识 CSS,CSS属性
  15. matlab负序,正序、负序、零序的定量计算方法举例
  16. 细谈中医------疥,疮,痘的治疗方法
  17. 前端知识总结之linux
  18. (入门)python的基本输入和输出
  19. 软件著作权申请步骤,注意事项(带图)
  20. Ionic在Generating ES5 bundles for differential loadind的时候报错

热门文章

  1. office 向程序发送命令时出现问题
  2. dw怎么在框架中加入网页_Dreamweaver如何用框架建立网站
  3. linux oracle实例名查看,Linux环境下oracle数库库改名,实例改名
  4. 12.3.5 子线程创建UdpSocket实例
  5. 华为freelance耳机充不进电修理
  6. Crypto_[QCTF2018]Xman-RSA
  7. “WebProxyWrapper”的对象强制转换为类型“System.Net.WebProxy
  8. Ubuntu:火狐浏览器加速下载(Flashgot+Aria2+Uget)
  9. Bad config encountered during initialization: No such notebook dir:
  10. chrome证书错误问题