w3resource

Python Calendar Module: itermonthdays() method

itermonthdays() method

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

Syntax:

itermonthdays(year, month)

Parameters:

Name Description Required /
Optional
Type
year Year for which the calendar should be generated. Required Number
month Month for which the calendar should be generated. Required Number

Example of itermonthdays() method

import calendar
cal= calendar.Calendar()
for x in cal.itermonthdays(2016, 5):
  print(x)

Output:

0
0
0
0
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
0
0
0
0
0

Note: itermonthdates: Return an iterator for the month month (1-12) in the year year. This 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.

Previous: itermonthdays2()
Next: monthdatescalendar()

Test your Python skills with w3resource's quiz



Python: Tips of the Day

What is the difference between Python's list methods append and extend?

append: Appends object at the end.

x = [1, 2, 3]
x.append([4, 5])
print (x)

Output:

[1, 2, 3, [4, 5]]

extend: Extends list by appending elements from the iterable.

x = [1, 2, 3]
x.extend([4, 5])
print (x)

Output:

[1, 2, 3, 4, 5]

Ref: https://bit.ly/2AZ6ZFq