ADVERTISEMENT
ADVERTISEMENT

Python Calendar Class | itermonthdays3() Method with Example

Python Calendar.itermonthdays3() Method: Here, we are going to learn about the itermonthdays3() method of Calendar class in Python with its definition, syntax, and examples.
Submitted by Hritika Rajput, on May 10, 2020

Python Calendar.itermonthdays3() Method

Calendar.itermonthdays3() method is an inbuilt method of the Calendar class of calendar module in Python. It uses an instance of this class and returns an iterator for the given month in the given year. The month consists of full weeks, ie, each week has full 7 values even if the value is outside of the month. An entry in a week is given by a tuple consisting of a year, a month and a day of the month numbers.

Module:

    import calendar

Class:

    from calendar import Calendar

Syntax:

    itermonthdays3(year, month)

Parameter(s):

  • year: It is a required parameter, which specifies the year of the calendar.
  • month: It is a required parameter, which specifies the month of the calendar.

Return value:

The return type of this method is <class 'generator'>, it returns an iterator for the month where each value is a tuple consisting of the year, month and date on that day.

Example:

# Python program to illustrate the 
# use of itermonthdays3() method

# import class
import calendar

# Creating Calendar Instance
cal = calendar.Calendar()
year = 2019
month = 12

print("Iterating over the weeks of December 2019 where each tuple is date, month and year")
for i in cal.itermonthdays3(year, month):
    print(i)
# first value is the day of the month; 
# days outside of the month is 0
# second value is weekday number where 
# Monday is 0 till Sunday which is 6
print()
print()

# set the firstweekday to 1
cal = calendar.Calendar(firstweekday = 1)
year = 1994
month = 9

print("Iterating over the weeks of September 1994 where each tuple is date, month and year and iterator starts with firstweekday as Tuesday")
for i in cal.itermonthdays3(year, month):
    print(i)
print()
print()

Output

Iterating over the weeks of December 2019 where each tuple is date, month and year
(2019, 11, 25)
(2019, 11, 26)
(2019, 11, 27)
(2019, 11, 28)
(2019, 11, 29)
(2019, 11, 30)
(2019, 12, 1)
(2019, 12, 2)
(2019, 12, 3)
(2019, 12, 4)
(2019, 12, 5)
(2019, 12, 6)
(2019, 12, 7)
(2019, 12, 8)
(2019, 12, 9)
(2019, 12, 10)
(2019, 12, 11)
(2019, 12, 12)
(2019, 12, 13)
(2019, 12, 14)
(2019, 12, 15)
(2019, 12, 16)
(2019, 12, 17)
(2019, 12, 18)
(2019, 12, 19)
(2019, 12, 20)
(2019, 12, 21)
(2019, 12, 22)
(2019, 12, 23)
(2019, 12, 24)
(2019, 12, 25)
(2019, 12, 26)
(2019, 12, 27)
(2019, 12, 28)
(2019, 12, 29)
(2019, 12, 30)
(2019, 12, 31)
(2020, 1, 1)
(2020, 1, 2)
(2020, 1, 3)
(2020, 1, 4)
(2020, 1, 5)


Iterating over the weeks of September 1994 where each tuple is date, month and year and iterator starts with firstweekday as Tuesday
(1994, 8, 30)
(1994, 8, 31)
(1994, 9, 1)
(1994, 9, 2)
(1994, 9, 3)
(1994, 9, 4)
(1994, 9, 5)
(1994, 9, 6)
(1994, 9, 7)
(1994, 9, 8)
(1994, 9, 9)
(1994, 9, 10)
(1994, 9, 11)
(1994, 9, 12)
(1994, 9, 13)
(1994, 9, 14)
(1994, 9, 15)
(1994, 9, 16)
(1994, 9, 17)
(1994, 9, 18)
(1994, 9, 19)
(1994, 9, 20)
(1994, 9, 21)
(1994, 9, 22)
(1994, 9, 23)
(1994, 9, 24)
(1994, 9, 25)
(1994, 9, 26)
(1994, 9, 27)
(1994, 9, 28)
(1994, 9, 29)
(1994, 9, 30)
(1994, 10, 1)
(1994, 10, 2)
(1994, 10, 3)
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.