{"id":25957,"date":"2021-12-03T21:29:28","date_gmt":"2021-12-03T15:59:28","guid":{"rendered":"https:\/\/python-programs.com\/?p=25957"},"modified":"2021-12-03T21:38:32","modified_gmt":"2021-12-03T16:08:32","slug":"python-program-for-calendar-itermonthdays2-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-calendar-itermonthdays2-method-with-examples\/","title":{"rendered":"Python Program for calendar itermonthdays2() Method with Examples"},"content":{"rendered":"
Calendar Module:<\/strong><\/p>\n The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely.<\/p>\n itermonthdays2() Method:<\/strong><\/p>\n The itermonthdays2() method, returns an iterator for the month in the year like itermonthdates(). Days will be returned as tuples of a day number and a week day number.<\/p>\n Syntax:<\/strong><\/p>\n Parameter Values:<\/strong><\/p>\n year:<\/strong>\u00a0This is required. It is a number. The year for which the calendar should be created.<\/p>\n month:\u00a0<\/strong>This is required. It is a number. The month for which the calendar should be created.<\/p>\n Return Value: <\/strong>Iterator for the month is returned.<\/p>\n Example1:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Calendar Module: The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely. itermonthdays2() Method: The itermonthdays2() method, returns an iterator for the month in the year like itermonthdates(). Days …<\/p>\nitermonthdays2(year, month)<\/pre>\n
Program for calendar itermonthdays2() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import calendar module using the import keyword.\r\nimport calendar\r\n# Give the year as static input and store it in a variable.\r\ngvn_yr = 2020\r\n# Give the month as static input and store it in another variable.\r\ngvn_mont = 4\r\n# Call the Calendar() function and store it in another variable.\r\ncalendr = calendar.Calendar()\r\n# Apply itermonthdays2() method to the above calendar by passing the given year,\r\n# month as the arguments and store it in another variable.\r\nrslt = calendr.itermonthdays2(gvn_yr, gvn_mont)\r\n# Iterate in the above result using the for loop.\r\nfor itr in rslt:\r\n # Inside the loop, print the iterator value.\r\n print(itr)\r\n<\/pre>\n
(0, 0)\r\n(0, 1)\r\n(1, 2)\r\n(2, 3)\r\n(3, 4)\r\n(4, 5)\r\n(5, 6)\r\n(6, 0)\r\n(7, 1)\r\n(8, 2)\r\n(9, 3)\r\n(10, 4)\r\n(11, 5)\r\n(12, 6)\r\n(13, 0)\r\n(14, 1)\r\n(15, 2)\r\n(16, 3)\r\n(17, 4)\r\n(18, 5)\r\n(19, 6)\r\n(20, 0)\r\n(21, 1)\r\n(22, 2)\r\n(23, 3)\r\n(24, 4)\r\n(25, 5)\r\n(26, 6)\r\n(27, 0)\r\n(28, 1)\r\n(29, 2)\r\n(30, 3)\r\n(0, 4)\r\n(0, 5)\r\n(0, 6)<\/pre>\n
\n
# Import calendar module using the import keyword.\r\nimport calendar\r\n# Give the year as static input and store it in a variable.\r\ngvn_yr = 2011\r\n# Give the month as static input and store it in another variable.\r\ngvn_mont = 6\r\n# Call the Calendar() function by setting firstweekday=2 and store it in\r\n# another variable.\r\ncalendr = calendar.Calendar(firstweekday=2)\r\n# Apply itermonthdays2() method to the above calendar by passing the given year,\r\n# month as the arguments and store it in another variable.\r\nrslt = calendr.itermonthdays2(gvn_yr, gvn_mont)\r\n# Iterate in the above result using the for loop.\r\nfor itr in rslt:\r\n # Inside the loop, print the iterator value.\r\n print(itr)\r\n<\/pre>\n
(1, 2)\r\n(2, 3)\r\n(3, 4)\r\n(4, 5)\r\n(5, 6)\r\n(6, 0)\r\n(7, 1)\r\n(8, 2)\r\n(9, 3)\r\n(10, 4)\r\n(11, 5)\r\n(12, 6)\r\n(13, 0)\r\n(14, 1)\r\n(15, 2)\r\n(16, 3)\r\n(17, 4)\r\n(18, 5)\r\n(19, 6)\r\n(20, 0)\r\n(21, 1)\r\n(22, 2)\r\n(23, 3)\r\n(24, 4)\r\n(25, 5)\r\n(26, 6)\r\n(27, 0)\r\n(28, 1)\r\n(29, 2)\r\n(30, 3)\r\n(0, 4)\r\n(0, 5)\r\n(0, 6)\r\n(0, 0)\r\n(0, 1)<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import calendar module using the import keyword.\r\nimport calendar\r\n# Give the year as user input using the int(input()) function and store it in a variable.\r\ngvn_yr = int(input(\"Enter some random year = \"))\r\n# Give the month as user input using the int(input()) function and store it in another variable.\r\ngvn_mont = int(input(\"Enter some random month = \"))\r\n# Call the Calendar() function and store it in another variable.\r\ncalendr = calendar.Calendar()\r\n# Apply itermonthdays2() method to the above calendar by passing the given year,\r\n# month as the arguments and store it in another variable.\r\nrslt = calendr.itermonthdays2(gvn_yr, gvn_mont)\r\n# Iterate in the above result using the for loop.\r\nfor itr in rslt:\r\n # Inside the loop, print the iterator value.\r\n print(itr)<\/pre>\n
Enter some random year = 2003\r\nEnter some random month = 2\r\n(0, 0)\r\n(0, 1)\r\n(0, 2)\r\n(0, 3)\r\n(0, 4)\r\n(1, 5)\r\n(2, 6)\r\n(3, 0)\r\n(4, 1)\r\n(5, 2)\r\n(6, 3)\r\n(7, 4)\r\n(8, 5)\r\n(9, 6)\r\n(10, 0)\r\n(11, 1)\r\n(12, 2)\r\n(13, 3)\r\n(14, 4)\r\n(15, 5)\r\n(16, 6)\r\n(17, 0)\r\n(18, 1)\r\n(19, 2)\r\n(20, 3)\r\n(21, 4)\r\n(22, 5)\r\n(23, 6)\r\n(24, 0)\r\n(25, 1)\r\n(26, 2)\r\n(27, 3)\r\n(28, 4)\r\n(0, 5)\r\n(0, 6)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"