Python calendar module | yeardayscalendar() method
Calendar module allows to output calendars like program, and provides additional useful functions related to the calendar. Functions and classes defined in Calendar module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions.
yeardayscalendar() method in Python is used to get the data for specified year. Entries in the week lists are day numbers. Day numbers outside this month are zero.
Syntax: yeardayscalendar(year, width) Parameter: year: year of the calendar width: [Default: 3] number of months in each row. Returns: list of day numbers.
Code #1:
# Python program to demonstrate working # of yeardayscalendar() method # importing calendar module import calendar obj = calendar.Calendar() year = 2016# default value of width is 3 # priting with yeardayscalendar print(obj.yeardayscalendar(year)) |
Output:
[[[[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]], [[1, 2, 3, 4, 5, 6, 7]…
…
[[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]]]]
Code #2: iterating the list of weeks
# Python program to demonstrate working # of yeardayscalendar() method # importing calendar module import calendar obj = calendar.Calendar() # iteratign with yeardayscalendar for day in obj.yeardayscalendar(2018, 1): print(day) |
Output:
[[[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]]]
[[[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, 0, 0, 0, 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, 0, 0, 0, 0]]]
Recommended Posts:
- Python calendar module | iterweekdays() method
- Python calendar module | itermonthdays() method
- Python calendar module | leapdays() method
- Python calendar module | itermonthdays2() method
- Python calendar module | isleap() method
- Python calendar module | firstweekday() method
- Python calendar module | pryear() method
- Python calendar module | yeardatescalendar() method
- Python calendar module | setfirstweekday() method
- Python calendar module | monthdatescalendar() method
- Python calendar module | monthdays2calendar() method
- Python calendar module | monthdayscalendar() method
- Python calendar module | itermonthdates() method
- Python calendar module | formatyear() method
- Python calendar module | yeardays2calendar() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



