Python calendar module | itermonthdays2() 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.

itermonthdays2() method is used to get an iterator for the month in the year similar to itermonthdates(). Days returned will simply be day of the month numbers. For the days outside of the specified month, the day number is 0.

Syntax: itermonthdays2(year, month)

Parameter:
year: year of the calendar
month: month of the calendar

Returns: an iterator for the month.

Code #1: Working example of itermonthdays2() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to demonstrate working
# of itermonthdates() method
  
# importing calendar module
import calendar
  
obj = calendar.Calendar()
  
# iterating with itermonthdays2
for day in obj.itermonthdays2(2018, 9):
    print(day)

chevron_right


Output:

The starting day number in calendar is : 0
(0, 0)
(0, 1)
(0, 2)
(0, 3)
(0, 4)
(1, 5)
(2, 6)
(3, 0)
.
.
(29, 5)
(30, 6)

 

Code #2 : Working example of itermonthdays2() method with firstweekday=2

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to demonstrate working
# of itermonthdates() method
  
# importing calendar module
import calendar
  
obj = calendar.Calendar(firstweekday = 2)
  
# iterating with parameter itermonthdays2
for day in obj.itermonthdays2(2018, 9):
    print(day)

chevron_right


Output:

(0, 2)
(0, 3)
(0, 4)
(1, 5)
(2, 6)
(3, 0)
(4, 1)
.
.
(27, 3)
(28, 4)
(29, 5)
(30, 6)
(0, 0)
(0, 1)


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.