Python Calendar Module : yeardatescalendar() method
yeardatescalendar() method
The yeardatescalendar() method is used to get the data for the specified year ready for formatting.
The return value is a list of month rows. Each month row contains up to width months.
Each month contains between 4 and 6 weeks and each week contains 1–7 days. Days are datetime.date objects.
Syntax:
yeardatescalendar(year, width=3)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
year | Year for which the calendar should be generated. | Required | Number |
width | The number of months to include in each row. Default: 3 | Required | Number |
Example of yeardatescalendar() method
import calendar
cal= calendar.Calendar()
print(cal.yeardatescalendar(2016, 3))
Output:
[[[[datetime.date(2015, 12, 28), datetime.date(2015, 12, 29), datetime.date(2015, 12, 30), datetime.date(2015, 12, 31), datetime.date(2016, 1, 1), datetime.date(2016, 1, 2), datetime.date(2016, 1, 3)], [datetime.date(2016, 1, 4), datetime.date(2016, 1, 5), datetime.date(2016, 1, 6), datetime.date(2016, 1, 7), datetime.date(2016, 1, 8), datetime.date(2016, 1, 9), datetime.date(2016, 1, 10)], ... , datetime.date(2016, 12, 27), datetime.date(2016, 12, 28), datetime.date(2016, 12, 29), datetime.date(2016, 12, 30), datetime.date(2016, 12, 31), datetime.date(2017, 1, 1)]]]]
Previous: monthdayscalendar()
Next: yeardays2calendar()
Test your Python skills with w3resource's quiz
Python: Tips of the Day
What is the difference between Python's list methods append and extend?
append: Appends object at the end.
x = [1, 2, 3] x.append([4, 5]) print (x)
Output:
[1, 2, 3, [4, 5]]
extend: Extends list by appending elements from the iterable.
x = [1, 2, 3] x.extend([4, 5]) print (x)
Output:
[1, 2, 3, 4, 5]
Ref: https://bit.ly/2AZ6ZFq
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework