w3resource

Python Calendar Module: itermonthdays2() method

itermonthdays2() method

The itermonthdays2() method is used to get an iterator for the month in the year similar to itermonthdates(). Days returned will be tuples consisting of a day number and a week day number.

Syntax

itermonthdays2(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 Python itermonthdates() method

import calendar
cal= calendar.Calendar()
for x in cal.itermonthdays2(2016, 5):
	print(x)

Output:

(0, 0)
(0, 1)
(0, 2)
(0, 3)
(0, 4)
(0, 5)
(1, 6)
(2, 0)
(3, 1)
(4, 2)
(5, 3)
(6, 4)
(7, 5)
(8, 6)
(9, 0)
(10, 1)
(11, 2)
(12, 3)
(13, 4)
(14, 5)
(15, 6)
(16, 0)
(17, 1)
(18, 2)
(19, 3)
(20, 4)
(21, 5)
(22, 6)
(23, 0)
(24, 1)
(25, 2)
(26, 3)
(27, 4)
(28, 5)
(29, 6)
(30, 0)
(31, 1)
(0, 2)
(0, 3)
(0, 4)
(0, 5)
(0, 6)

Note: itermonthdates

Return an iterator for the month month (1-12) in the year 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.

Previous: itermonthdates()
Next: itermonthdays()

Test your Python skills with w3resource's quiz



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python/module/calendar/itermonthdays2.php