Python Calendar.monthdayscalendar() 方法
Calendar.monthdayscalendar() 方法是内置的方法Calendar
类calendar
Python 中的模块。它使用此类的实例并返回给定年份给定月份中的周列表作为完整周。周是七个数字的列表。如果一周中某一天的值为 0,则表示它不属于该月。
模块:
import calendar
类:
from calendar import Calendar
用法:
monthdayscalendar(year, month)
参数:
year
:它是一个必需参数,它指定日历的年份。month
:它是一个必需参数,它指定日历的月份。
返回值:
这个方法的返回类型是<class 'list'>
,它将给定月份中的周列表作为完整周返回,即,每周由 7 个值组成。这里有 0 值的天意味着他们不在那个月。
例:
# Python program to illustrate the
# use of monthdayscalendar() method
# import class
import calendar
# Creating Calendar Instance
cal = calendar.Calendar()
# default firstweekday =0
year = 2011
month = 11
print("Days outside of the month are 0")
print("Weekwise calendar of November 2011 with first weekday as Monday")
print(cal.monthdayscalendar(year, month))
print()
# always full weeks are listed.
# set the firstweekday to 3
cal = calendar.Calendar(firstweekday = 3)
year = 1998
month = 8
print("Weekwise calendar of August 1998 with first weekday as Thursday")
print(cal.monthdayscalendar(year, month))
print()
输出
Days outside of the month are 0 Weekwise calendar of November 2011 with first weekday as Monday [ [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, 0] ] Weekwise calendar of August 1998 with first weekday as Thursday [ [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] ]
相关用法
- Python Calendar monthdays2calendar()用法及代码示例
- Python Calendar monthdatescalendar()用法及代码示例
- Python Calendar itermonthdays2()用法及代码示例
- Python Calendar itermonthdates()用法及代码示例
- Python Calendar iterweekdays()用法及代码示例
- Python Calendar itermonthdays3()用法及代码示例
- Python Calendar itermonthdays4()用法及代码示例
- Python Calendar yeardatescalendar()用法及代码示例
- Python Calendar itermonthdays()用法及代码示例
- Python Calendar yeardayscalendar()用法及代码示例
- Python Calendar yeardays2calendar()用法及代码示例
- Python Condition release()用法及代码示例
- Python Collections.UserString用法及代码示例
- Python Condition notify()用法及代码示例
- Python Condition wait()用法及代码示例
- Python Sympy Curve.translate()用法及代码示例
- Python Collections.UserDict用法及代码示例
- Python Collections.UserList用法及代码示例
- Python Condition notify_all()用法及代码示例
- Python Condition acquire()用法及代码示例
注:本文由纯净天空筛选整理自 Python Calendar Class | monthdayscalendar() Method with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。