Python Calendar.yeardatescalendar() 方法
Calendar.yeardatescalendar() 方法是內置的方法Calendar
類calendar
Python 中的模塊。它使用此類的實例並返回給定年份的月份行列表。
在這裏,每個月都包含完整的周,即一個月中的所有周都有 7 個值,即使一周中一天的值在給定月份之外。每個周列表由七個 datetime.date 對象組成。
模塊:
import calendar
類:
from calendar import Calendar
用法:
yeardatescalendar(year, width =3)
參數:
year
:它是一個必需參數,它指定日曆的年份。width
: 可選參數,指定月份值的寬度;默認值 = 3。
返回值:
這個方法的返回類型是<class 'list'>
,它返回給出 datetime.date 對象的月份行列表。
例:
# 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(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(cal.monthdayscalendar(year, month))
print()
輸出
[[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]] [[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 program to illustrate the
# use of yeardatescalendar() method
# import class
import calendar
# Creating Calendar Instance
cal = calendar.Calendar()
year = 2019
# Changing the width to 5
print(cal.yeardatescalendar(year, width = 5))
print()
輸出
[[[[ datetime.date(2018, 12, 31), datetime.date(2019, 1, 1), datetime.date(2019, 1, 2), datetime.date(2019, 1, 3), datetime.date(2019, 1, 4), datetime.date(2019, 1, 5), datetime.date(2019, 1, 6), ], [ datetime.date(2019, 1, 7), datetime.date(2019, 1, 8), datetime.date(2019, 1, 9), datetime.date(2019, 1, 10), datetime.date(2019, 1, 11), datetime.date(2019, 1, 12), datetime.date(2019, 1, 13), ], [ datetime.date(2019, 1, 14), datetime.date(2019, 1, 15), datetime.date(2019, 1, 16), datetime.date(2019, 1, 17), datetime.date(2019, 1, 18), datetime.date(2019, 1, 19), datetime.date(2019, 1, 20), ], [ datetime.date(2019, 1, 21), datetime.date(2019, 1, 22), datetime.date(2019, 1, 23), datetime.date(2019, 1, 24), datetime.date(2019, 1, 25), datetime.date(2019, 1, 26), datetime.date(2019, 1, 27), ], [ datetime.date(2019, 1, 28), datetime.date(2019, 1, 29), datetime.date(2019, 1, 30), datetime.date(2019, 1, 31), datetime.date(2019, 2, 1), datetime.date(2019, 2, 2), datetime.date(2019, 2, 3), ]], [[ datetime.date(2019, 1, 28), datetime.date(2019, 1, 29), datetime.date(2019, 1, 30), datetime.date(2019, 1, 31), datetime.date(2019, 2, 1), datetime.date(2019, 2, 2), datetime.date(2019, 2, 3), ], [ datetime.date(2019, 2, 4), datetime.date(2019, 2, 5), datetime.date(2019, 2, 6), datetime.date(2019, 2, 7), datetime.date(2019, 2, 8), datetime.date(2019, 2, 9), datetime.date(2019, 2, 10), ], [ datetime.date(2019, 2, 11), datetime.date(2019, 2, 12), datetime.date(2019, 2, 13), datetime.date(2019, 2, 14), datetime.date(2019, 2, 15), datetime.date(2019, 2, 16), datetime.date(2019, 2, 17), ], [ datetime.date(2019, 2, 18), datetime.date(2019, 2, 19), datetime.date(2019, 2, 20), datetime.date(2019, 2, 21), datetime.date(2019, 2, 22), datetime.date(2019, 2, 23), datetime.date(2019, 2, 24), ], [ datetime.date(2019, 2, 25), datetime.date(2019, 2, 26), datetime.date(2019, 2, 27), datetime.date(2019, 2, 28), datetime.date(2019, 3, 1), datetime.date(2019, 3, 2), datetime.date(2019, 3, 3), ]], [[ datetime.date(2019, 2, 25), datetime.date(2019, 2, 26), datetime.date(2019, 2, 27), datetime.date(2019, 2, 28), datetime.date(2019, 3, 1), datetime.date(2019, 3, 2), datetime.date(2019, 3, 3), ], [ datetime.date(2019, 3, 4), datetime.date(2019, 3, 5), datetime.date(2019, 3, 6), datetime.date(2019, 3, 7), datetime.date(2019, 3, 8), datetime.date(2019, 3, 9), datetime.date(2019, 3, 10), ], [ datetime.date(2019, 3, 11), datetime.date(2019, 3, 12), datetime.date(2019, 3, 13), datetime.date(2019, 3, 14), datetime.date(2019, 3, 15), datetime.date(2019, 3, 16), datetime.date(2019, 3, 17), ], [ datetime.date(2019, 3, 18), datetime.date(2019, 3, 19), datetime.date(2019, 3, 20), datetime.date(2019, 3, 21), datetime.date(2019, 3, 22), datetime.date(2019, 3, 23), datetime.date(2019, 3, 24), ], [ datetime.date(2019, 3, 25), datetime.date(2019, 3, 26), datetime.date(2019, 3, 27), datetime.date(2019, 3, 28), datetime.date(2019, 3, 29), datetime.date(2019, 3, 30), datetime.date(2019, 3, 31), ]], [[ datetime.date(2019, 4, 1), datetime.date(2019, 4, 2), datetime.date(2019, 4, 3), datetime.date(2019, 4, 4), datetime.date(2019, 4, 5), datetime.date(2019, 4, 6), datetime.date(2019, 4, 7), ], [ datetime.date(2019, 4, 8), datetime.date(2019, 4, 9), datetime.date(2019, 4, 10), datetime.date(2019, 4, 11), datetime.date(2019, 4, 12), datetime.date(2019, 4, 13), datetime.date(2019, 4, 14), ], [ datetime.date(2019, 4, 15), datetime.date(2019, 4, 16), datetime.date(2019, 4, 17), datetime.date(2019, 4, 18), datetime.date(2019, 4, 19), datetime.date(2019, 4, 20), datetime.date(2019, 4, 21), ], [ datetime.date(2019, 4, 22), datetime.date(2019, 4, 23), datetime.date(2019, 4, 24), datetime.date(2019, 4, 25), datetime.date(2019, 4, 26), datetime.date(2019, 4, 27), datetime.date(2019, 4, 28), ], [ datetime.date(2019, 4, 29), datetime.date(2019, 4, 30), datetime.date(2019, 5, 1), datetime.date(2019, 5, 2), datetime.date(2019, 5, 3), datetime.date(2019, 5, 4), datetime.date(2019, 5, 5), ]], [[ datetime.date(2019, 4, 29), datetime.date(2019, 4, 30), datetime.date(2019, 5, 1), datetime.date(2019, 5, 2), datetime.date(2019, 5, 3), datetime.date(2019, 5, 4), datetime.date(2019, 5, 5), ], [ datetime.date(2019, 5, 6), datetime.date(2019, 5, 7), datetime.date(2019, 5, 8), datetime.date(2019, 5, 9), datetime.date(2019, 5, 10), datetime.date(2019, 5, 11), datetime.date(2019, 5, 12), ], [ datetime.date(2019, 5, 13), datetime.date(2019, 5, 14), datetime.date(2019, 5, 15), datetime.date(2019, 5, 16), datetime.date(2019, 5, 17), datetime.date(2019, 5, 18), datetime.date(2019, 5, 19), ], [ datetime.date(2019, 5, 20), datetime.date(2019, 5, 21), datetime.date(2019, 5, 22), datetime.date(2019, 5, 23), datetime.date(2019, 5, 24), datetime.date(2019, 5, 25), datetime.date(2019, 5, 26), ], [ datetime.date(2019, 5, 27), datetime.date(2019, 5, 28), datetime.date(2019, 5, 29), datetime.date(2019, 5, 30), datetime.date(2019, 5, 31), datetime.date(2019, 6, 1), datetime.date(2019, 6, 2), ]]], [[[ datetime.date(2019, 5, 27), datetime.date(2019, 5, 28), datetime.date(2019, 5, 29), datetime.date(2019, 5, 30), datetime.date(2019, 5, 31), datetime.date(2019, 6, 1), datetime.date(2019, 6, 2), ], [ datetime.date(2019, 6, 3), datetime.date(2019, 6, 4), datetime.date(2019, 6, 5), datetime.date(2019, 6, 6), datetime.date(2019, 6, 7), datetime.date(2019, 6, 8), datetime.date(2019, 6, 9), ], [ datetime.date(2019, 6, 10), datetime.date(2019, 6, 11), datetime.date(2019, 6, 12), datetime.date(2019, 6, 13), datetime.date(2019, 6, 14), datetime.date(2019, 6, 15), datetime.date(2019, 6, 16), ], [ datetime.date(2019, 6, 17), datetime.date(2019, 6, 18), datetime.date(2019, 6, 19), datetime.date(2019, 6, 20), datetime.date(2019, 6, 21), datetime.date(2019, 6, 22), datetime.date(2019, 6, 23), ], [ datetime.date(2019, 6, 24), datetime.date(2019, 6, 25), datetime.date(2019, 6, 26), datetime.date(2019, 6, 27), datetime.date(2019, 6, 28), datetime.date(2019, 6, 29), datetime.date(2019, 6, 30), ]], [[ datetime.date(2019, 7, 1), datetime.date(2019, 7, 2), datetime.date(2019, 7, 3), datetime.date(2019, 7, 4), datetime.date(2019, 7, 5), datetime.date(2019, 7, 6), datetime.date(2019, 7, 7), ], [ datetime.date(2019, 7, 8), datetime.date(2019, 7, 9), datetime.date(2019, 7, 10), datetime.date(2019, 7, 11), datetime.date(2019, 7, 12), datetime.date(2019, 7, 13), datetime.date(2019, 7, 14), ], [ datetime.date(2019, 7, 15), datetime.date(2019, 7, 16), datetime.date(2019, 7, 17), datetime.date(2019, 7, 18), datetime.date(2019, 7, 19), datetime.date(2019, 7, 20), datetime.date(2019, 7, 21), ], [ datetime.date(2019, 7, 22), datetime.date(2019, 7, 23), datetime.date(2019, 7, 24), datetime.date(2019, 7, 25), datetime.date(2019, 7, 26), datetime.date(2019, 7, 27), datetime.date(2019, 7, 28), ], [ datetime.date(2019, 7, 29), datetime.date(2019, 7, 30), datetime.date(2019, 7, 31), datetime.date(2019, 8, 1), datetime.date(2019, 8, 2), datetime.date(2019, 8, 3), datetime.date(2019, 8, 4), ]], [[ datetime.date(2019, 7, 29), datetime.date(2019, 7, 30), datetime.date(2019, 7, 31), datetime.date(2019, 8, 1), datetime.date(2019, 8, 2), datetime.date(2019, 8, 3), datetime.date(2019, 8, 4), ], [ datetime.date(2019, 8, 5), datetime.date(2019, 8, 6), datetime.date(2019, 8, 7), datetime.date(2019, 8, 8), datetime.date(2019, 8, 9), datetime.date(2019, 8, 10), datetime.date(2019, 8, 11), ], [ datetime.date(2019, 8, 12), datetime.date(2019, 8, 13), datetime.date(2019, 8, 14), datetime.date(2019, 8, 15), datetime.date(2019, 8, 16), datetime.date(2019, 8, 17), datetime.date(2019, 8, 18), ], [ datetime.date(2019, 8, 19), datetime.date(2019, 8, 20), datetime.date(2019, 8, 21), datetime.date(2019, 8, 22), datetime.date(2019, 8, 23), datetime.date(2019, 8, 24), datetime.date(2019, 8, 25), ], [ datetime.date(2019, 8, 26), datetime.date(2019, 8, 27), datetime.date(2019, 8, 28), datetime.date(2019, 8, 29), datetime.date(2019, 8, 30), datetime.date(2019, 8, 31), datetime.date(2019, 9, 1), ]], [ [ datetime.date(2019, 8, 26), datetime.date(2019, 8, 27), datetime.date(2019, 8, 28), datetime.date(2019, 8, 29), datetime.date(2019, 8, 30), datetime.date(2019, 8, 31), datetime.date(2019, 9, 1), ], [ datetime.date(2019, 9, 2), datetime.date(2019, 9, 3), datetime.date(2019, 9, 4), datetime.date(2019, 9, 5), datetime.date(2019, 9, 6), datetime.date(2019, 9, 7), datetime.date(2019, 9, 8), ], [ datetime.date(2019, 9, 9), datetime.date(2019, 9, 10), datetime.date(2019, 9, 11), datetime.date(2019, 9, 12), datetime.date(2019, 9, 13), datetime.date(2019, 9, 14), datetime.date(2019, 9, 15), ], [ datetime.date(2019, 9, 16), datetime.date(2019, 9, 17), datetime.date(2019, 9, 18), datetime.date(2019, 9, 19), datetime.date(2019, 9, 20), datetime.date(2019, 9, 21), datetime.date(2019, 9, 22), ], [ datetime.date(2019, 9, 23), datetime.date(2019, 9, 24), datetime.date(2019, 9, 25), datetime.date(2019, 9, 26), datetime.date(2019, 9, 27), datetime.date(2019, 9, 28), datetime.date(2019, 9, 29), ], [ datetime.date(2019, 9, 30), datetime.date(2019, 10, 1), datetime.date(2019, 10, 2), datetime.date(2019, 10, 3), datetime.date(2019, 10, 4), datetime.date(2019, 10, 5), datetime.date(2019, 10, 6), ], ], [[ datetime.date(2019, 9, 30), datetime.date(2019, 10, 1), datetime.date(2019, 10, 2), datetime.date(2019, 10, 3), datetime.date(2019, 10, 4), datetime.date(2019, 10, 5), datetime.date(2019, 10, 6), ], [ datetime.date(2019, 10, 7), datetime.date(2019, 10, 8), datetime.date(2019, 10, 9), datetime.date(2019, 10, 10), datetime.date(2019, 10, 11), datetime.date(2019, 10, 12), datetime.date(2019, 10, 13), ], [ datetime.date(2019, 10, 14), datetime.date(2019, 10, 15), datetime.date(2019, 10, 16), datetime.date(2019, 10, 17), datetime.date(2019, 10, 18), datetime.date(2019, 10, 19), datetime.date(2019, 10, 20), ], [ datetime.date(2019, 10, 21), datetime.date(2019, 10, 22), datetime.date(2019, 10, 23), datetime.date(2019, 10, 24), datetime.date(2019, 10, 25), datetime.date(2019, 10, 26), datetime.date(2019, 10, 27), ], [ datetime.date(2019, 10, 28), datetime.date(2019, 10, 29), datetime.date(2019, 10, 30), datetime.date(2019, 10, 31), datetime.date(2019, 11, 1), datetime.date(2019, 11, 2), datetime.date(2019, 11, 3), ]]], [[[ datetime.date(2019, 10, 28), datetime.date(2019, 10, 29), datetime.date(2019, 10, 30), datetime.date(2019, 10, 31), datetime.date(2019, 11, 1), datetime.date(2019, 11, 2), datetime.date(2019, 11, 3), ], [ datetime.date(2019, 11, 4), datetime.date(2019, 11, 5), datetime.date(2019, 11, 6), datetime.date(2019, 11, 7), datetime.date(2019, 11, 8), datetime.date(2019, 11, 9), datetime.date(2019, 11, 10), ], [ datetime.date(2019, 11, 11), datetime.date(2019, 11, 12), datetime.date(2019, 11, 13), datetime.date(2019, 11, 14), datetime.date(2019, 11, 15), datetime.date(2019, 11, 16), datetime.date(2019, 11, 17), ], [ datetime.date(2019, 11, 18), datetime.date(2019, 11, 19), datetime.date(2019, 11, 20), datetime.date(2019, 11, 21), datetime.date(2019, 11, 22), datetime.date(2019, 11, 23), datetime.date(2019, 11, 24), ], [ datetime.date(2019, 11, 25), datetime.date(2019, 11, 26), datetime.date(2019, 11, 27), datetime.date(2019, 11, 28), datetime.date(2019, 11, 29), datetime.date(2019, 11, 30), datetime.date(2019, 12, 1), ]], [ [ datetime.date(2019, 11, 25), datetime.date(2019, 11, 26), datetime.date(2019, 11, 27), datetime.date(2019, 11, 28), datetime.date(2019, 11, 29), datetime.date(2019, 11, 30), datetime.date(2019, 12, 1), ], [ datetime.date(2019, 12, 2), datetime.date(2019, 12, 3), datetime.date(2019, 12, 4), datetime.date(2019, 12, 5), datetime.date(2019, 12, 6), datetime.date(2019, 12, 7), datetime.date(2019, 12, 8), ], [ datetime.date(2019, 12, 9), datetime.date(2019, 12, 10), datetime.date(2019, 12, 11), datetime.date(2019, 12, 12), datetime.date(2019, 12, 13), datetime.date(2019, 12, 14), datetime.date(2019, 12, 15), ], [ datetime.date(2019, 12, 16), datetime.date(2019, 12, 17), datetime.date(2019, 12, 18), datetime.date(2019, 12, 19), datetime.date(2019, 12, 20), datetime.date(2019, 12, 21), datetime.date(2019, 12, 22), ], [ datetime.date(2019, 12, 23), datetime.date(2019, 12, 24), datetime.date(2019, 12, 25), datetime.date(2019, 12, 26), datetime.date(2019, 12, 27), datetime.date(2019, 12, 28), datetime.date(2019, 12, 29), ], [ datetime.date(2019, 12, 30), datetime.date(2019, 12, 31), datetime.date(2020, 1, 1), datetime.date(2020, 1, 2), datetime.date(2020, 1, 3), datetime.date(2020, 1, 4), datetime.date(2020, 1, 5), ], ]]]
相關用法
- Python Calendar yeardayscalendar()用法及代碼示例
- Python Calendar yeardays2calendar()用法及代碼示例
- Python Calendar itermonthdays2()用法及代碼示例
- Python Calendar monthdatescalendar()用法及代碼示例
- Python Calendar itermonthdates()用法及代碼示例
- Python Calendar iterweekdays()用法及代碼示例
- Python Calendar monthdayscalendar()用法及代碼示例
- Python Calendar itermonthdays3()用法及代碼示例
- Python Calendar itermonthdays4()用法及代碼示例
- Python Calendar itermonthdays()用法及代碼示例
- Python Calendar monthdays2calendar()用法及代碼示例
- 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 | yeardatescalendar() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。