Python Calendar Module | itermonthdays2 () method

Python Methods and Functions

itermonthdays2() is used to get an iterator for the month of the year, similar to itermonthdates () . The days returned will be simply the days of the month. For days outside 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 the itermonthdays2 () method

# Python demo program
# of the itermonthdates () method

  
# importing the calendar module

import calendar

  

obj = calendar.Calendar ()

 
# iterate with itermonthdays2

for day in obj.itermonthdays2 ( 2018 , 9 ):

print (day)

Exit:

 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

# Python program to demonstrate how it works
# itermonthdates () method

 
# import calendar module

import calendar

 

obj = calendar.Calendar (firstweekday = 2 )

 
# iterate with itermonthdays2

for day   in obj.itermonthdays2 ( 2018 , 9 ):

print (day)

Exit :

 (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) 




Get Solution for free from DataCamp guru