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.
Previous: iterweekdays()
Next: itermonthdays2()
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Maps the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value:
Example:
def tips_map_dictionary(itr, fn): ret = {} for a in itr: ret[a] = fn(a) return ret print(tips_map_dictionary([2,4,6], lambda a: a * a))
Output:
{2: 4, 4: 16, 6: 36}
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook