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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。