ADVERTISEMENT
ADVERTISEMENT

Python Calendar Class | itermonthdates() Method with Example

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

Python Calendar.itermonthdates() Method

Calendar.itermonthdates() 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(1–12) in the given year. The iterator will return all days (as datetime.date objects) for the month and all days before the start of the month or after the end of the month that are required to get a complete week.

Module:

    import calendar

Class:

    from calendar import Calendar

Syntax:

    itermonthdates(year, month)

Parameter(s):

  • year: represents the year of the calendar
  • month: represents month of the calendar

Return value:

The function returns an iterator for the given month of the given year.

Example:

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

# import class
import calendar

# Creating Calendar Instance
cal = calendar.Calendar()
year = 2020
month = 2
# Complete weeks will be printed
for i in cal.itermonthdates(year, month):
    print(i)
print()

# Setting firstweekday value to 3
cal = calendar.Calendar(firstweekday = 3)
year = 2016
month = 2
for i in cal.itermonthdates(year, month):
    print(i)

Output

2020-01-27
2020-01-28
2020-01-29
2020-01-30
2020-01-31
2020-02-01
2020-02-02
2020-02-03
2020-02-04
2020-02-05
2020-02-06
2020-02-07
2020-02-08
2020-02-09
2020-02-10
2020-02-11
2020-02-12
2020-02-13
2020-02-14
2020-02-15
2020-02-16
2020-02-17
2020-02-18
2020-02-19
2020-02-20
2020-02-21
2020-02-22
2020-02-23
2020-02-24
2020-02-25
2020-02-26
2020-02-27
2020-02-28
2020-02-29
2020-03-01

2016-01-28
2016-01-29
2016-01-30
2016-01-31
2016-02-01
2016-02-02
2016-02-03
2016-02-04
2016-02-05
2016-02-06
2016-02-07
2016-02-08
2016-02-09
2016-02-10
2016-02-11
2016-02-12
2016-02-13
2016-02-14
2016-02-15
2016-02-16
2016-02-17
2016-02-18
2016-02-19
2016-02-20
2016-02-21
2016-02-22
2016-02-23
2016-02-24
2016-02-25
2016-02-26
2016-02-27
2016-02-28
2016-02-29
2016-03-01
2016-03-02

Reference: calendar.Calendar.itermonthdates

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.