{"id":25954,"date":"2021-12-03T21:38:31","date_gmt":"2021-12-03T16:08:31","guid":{"rendered":"https:\/\/python-programs.com\/?p=25954"},"modified":"2021-12-03T21:38:31","modified_gmt":"2021-12-03T16:08:31","slug":"python-program-for-calendar-itermonthdays-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-calendar-itermonthdays-method-with-examples\/","title":{"rendered":"Python Program for calendar itermonthdays() 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 itermonthdays() Method:<\/strong><\/p>\n The itermonthdays() method returns an iterator for a month and year given. The days returned will be merely day numbers. The procedure is similar to itermonthdates ().<\/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><\/p>\n The iterator of the chosen 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. itermonthdays() Method: The itermonthdays() method returns an iterator for a month and year given. The days returned …<\/p>\nitermonthdays(year, month)<\/pre>\n
Program for calendar itermonthdays() 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 = 2015\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 itermonthdays() 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.itermonthdays(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\r\n0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n0\r\n0\r\n0<\/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 = 2012\r\n# Give the month as static input and store it in another variable.\r\ngvn_mont = 5\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 itermonthdays() 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.itermonthdays(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
0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n0\r\n0\r\n0\r\n0\r\n0<\/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 itermonthdays() 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.itermonthdays(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 = 2005\r\nEnter some random month = 7\r\n0\r\n0\r\n0\r\n0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31<\/pre>\n","protected":false},"excerpt":{"rendered":"