Python Calendar Module: itermonthdays2() method
itermonthdays2() method
The itermonthdays2() method is used to get an iterator for the month in the year similar to itermonthdates(). Days returned will be tuples consisting of a day number and a week day number.
Syntax
itermonthdays2(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 Python itermonthdates() method
import calendar
cal= calendar.Calendar()
for x in cal.itermonthdays2(2016, 5):
print(x)
Output:
(0, 0) (0, 1) (0, 2) (0, 3) (0, 4) (0, 5) (1, 6) (2, 0) (3, 1) (4, 2) (5, 3) (6, 4) (7, 5) (8, 6) (9, 0) (10, 1) (11, 2) (12, 3) (13, 4) (14, 5) (15, 6) (16, 0) (17, 1) (18, 2) (19, 3) (20, 4) (21, 5) (22, 6) (23, 0) (24, 1) (25, 2) (26, 3) (27, 4) (28, 5) (29, 6) (30, 0) (31, 1) (0, 2) (0, 3) (0, 4) (0, 5) (0, 6)
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: itermonthdates()
Next: itermonthdays()
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
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework