Open In App

Python calendar module : itermonthdays() method

Last Updated : 13 May, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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: 

Python3
# Python program to demonstrate working
# of itermonthdays() method

# importing calendar module
import calendar

year = 2018
month = 9


obj = calendar.Calendar()

# iterating with itermonthdays
for day in obj.itermonthdays(year, month):
    print(day)

Output: 

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


Code #2: 

Python3
# Python program to demonstrate working
# of itermonthdays() method

# importing calendar module
import calendar

# use with firstweekday = 5
obj = calendar.Calendar(firstweekday = 2)

# iterating with itermonthdays
for day in obj.itermonthdays(2018, 4):
    print(day)

Output: 

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


 


Next Article

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy