Python Calendar Module: itermonthdates() method
itermonthdates() method
The itermonthdates() method returns an iterator for the month (1-12) in the year.
This iterator will return all days (as datetime.date objects) for the month and all days before the start of the month or after the end of the month that are required to get a complete week.
Syntax:
itermonthdates(year, month)
Parameters:
| Name | Description | Required / Optional |
Type |
|---|---|---|---|
| year | Year for which the calendar should be generated. | Required | Number |
| month | Month for which the calendar should be generated. | Required | Number |
Example of itermonthdates() method
import calendar
cal= calendar.Calendar()
for x in cal.itermonthdates(2016, 5):
print(x)
Output:
2016年04月25日 2016年04月26日 2016年04月27日 2016年04月28日 2016年04月29日 2016年04月30日 2016年05月01日 2016年05月02日 2016年05月03日 2016年05月04日 2016年05月05日 2016年05月06日 2016年05月07日 2016年05月08日 2016年05月09日 2016年05月10日 2016年05月11日 2016年05月12日 2016年05月13日 2016年05月14日 2016年05月15日 2016年05月16日 2016年05月17日 2016年05月18日 2016年05月19日 2016年05月20日 2016年05月21日 2016年05月22日 2016年05月23日 2016年05月24日 2016年05月25日 2016年05月26日 2016年05月27日 2016年05月28日 2016年05月29日 2016年05月30日 2016年05月31日 2016年06月01日 2016年06月02日 2016年06月03日 2016年06月04日 2016年06月05日
Note: datetime.date : A date object represents a date (year, month and day) in an idealized calendar, the current Gregorian calendar indefinitely extended in both directions. January 1 of year 1 is called day number 1, January 2 of year 1 is called day number 2, and so on.
PREV : iterweekdays()
NEXT : itermonthdays2()
Test your Python skills with w3resource's quiz