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

itermonthdays() method returns an iterator of a specified month and a year. Days returned will simply be day numbers. itermonthdays() method is similar to itermonthdates().

Syntax: itermonthdays(year, month)

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

Returns: an iterator of the specified month.

Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to demonstrate working
# of itermonthdays() method
  
# importing calendar module
import calendar
  
year = 2018
mnth = 9
  
  
obj = calendar.Calendar()
  
# iteratign with itermonthdays
for day in obj.itermonthdays(year, mnth):
    print(day)

chevron_right


Output:

0
0
0
0
0
1
2
3
4
5
6
.
.
29
30

Code #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to demonstrate working
# of itermonthdays() method
  
# importing calendar module
import calendar
  
# use with firstweekday = 5
obj = calendar.Calendar(firstweekday = 2)
  
# iteratign with itermonthdays
for day in obj.itermonthdays(2018, 4):
    print(day)

chevron_right


Output:

0
0
0
0
1
2
3
4
5
.
.
28
29
30
0


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.