{"id":25941,"date":"2021-12-03T21:38:28","date_gmt":"2021-12-03T16:08:28","guid":{"rendered":"https:\/\/python-programs.com\/?p=25941"},"modified":"2021-12-03T21:38:28","modified_gmt":"2021-12-03T16:08:28","slug":"python-program-for-calendar-iterweekdays-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-calendar-iterweekdays-method-with-examples\/","title":{"rendered":"Python Program for calendar iterweekdays() 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 iterweekdays() method:<\/strong><\/p>\n The iterweekdays() method returns an iterator of weekday numbers for one week. The first number returned by the iterator will be the same as the firstweekday() returned number.<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong> This method has no parameters.<\/p>\n Return Value:<\/strong> Returns an iterator of weekday numbers.<\/p>\n Example1:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/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. iterweekdays() method: The iterweekdays() method returns an iterator of weekday numbers for one week. The first number …<\/p>\niterweekdays()<\/pre>\n
Program for calendar iterweekdays() 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# Set the firstweekday=0 using the Calendar() function by passing the\r\n# firstweekday=0 as an argument.\r\n# Store it in a variable.\r\ncalendr = calendar.Calendar(firstweekday=0)\r\n# Apply the iterweekdays() method for the above result and store it in\r\n# another variable.\r\nrslt = calendr.iterweekdays()\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\n1\r\n2\r\n3\r\n4\r\n5\r\n6<\/pre>\n
It prints the seven days of the week starting from 0<\/pre>\n
\n
# Import calendar module using the import keyword.\r\nimport calendar\r\n# Set the firstweekday=2 using the Calendar() function by passing the\r\n# firstweekday=2 as an argument.\r\n# Store it in a variable.\r\ncalendr = calendar.Calendar(firstweekday=2)\r\n# Apply the iterweekdays() method for the above result and store it in\r\n# another variable.\r\nrslt = calendr.iterweekdays()\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
2\r\n3\r\n4\r\n5\r\n6\r\n0\r\n1<\/pre>\n
It prints the seven days of the week starting from 2<\/pre>\n","protected":false},"excerpt":{"rendered":"