

{"id":29055,"date":"2018-11-23T09:50:00","date_gmt":"2018-11-23T04:20:00","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=27587"},"modified":"2026-04-23T15:38:21","modified_gmt":"2026-04-23T10:08:21","slug":"python-calendar-module","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/","title":{"rendered":"Python Calendar Module | Calendar Class &amp; HTML Calendar"},"content":{"rendered":"<p><span style=\"font-weight: 400\">We took a brief look at the Python Calendar module when we talked about <\/span>Python date and time<span style=\"font-weight: 400\">. Let\u2019s take a deeper look at the Calendar Module in <\/span>Python<span style=\"font-weight: 400\"> now. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, we will talk about three classes in the calendar module- Calendar, TextCalendar, and HTMLCalendar. Also, we will take a look at their available instance methods. <\/span><\/p>\n<p><span style=\"font-weight: 400\">At last, we will learn about the available functions in the Python Calendar Modules.<\/span><\/p>\n<p><span style=\"font-weight: 400\">So, let\u2019s start the Python Calendar Module tutorial.<\/span><\/p>\n<div id=\"attachment_42729\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-42729\" class=\"size-full wp-image-42729\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg\" alt=\"Python Calendar Module\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-42729\" class=\"wp-caption-text\">Python Calendar Module<\/p><\/div>\n<h3><span style=\"font-weight: 400\">What is Python Calendar?<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Python Calendar Module lets you print calendars and perform functions related to those. These calendars begin at Monday (day=0) and end at Sunday (day=6). <\/span><\/p>\n<p><span style=\"font-weight: 400\">In this Python calendar tutorial, we will notice the Gregorian calendar, set indefinitely in both directions, as the base calendar. <\/span><\/p>\n<p><span style=\"font-weight: 400\">The ISO 8601 standard decides how to interpret zero and negative years. <\/span><span style=\"font-weight: 400\">We call year 0 \u20181 BC\u2019, year -1 \u20182 BC\u2019, and so on.<\/span><\/p>\n<p><span style=\"font-weight: 400\">This module holds the Calendar class that lends us various functions to manipulate date and time. Other than that, we have the TextCalendar and HTMLCalendar classes to produce pre-formatted output.<\/span><\/p>\n<p><span style=\"font-weight: 400\">We can import this Python Calendar Module as-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import calendar as cd<\/pre>\n<h3>Python Calendar Class<\/h3>\n<p><span style=\"font-weight: 400\">The first class we discuss here is the Calendar. The constructor for this has the following syntax:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">class calendar.Calendar(firstweekday=0)<\/pre>\n<p><span style=\"font-weight: 400\">This creates a Calendar object with whichever day of the week we want it to begin at. By default, it starts at Monday with a parameter value of 0. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Like we said earlier, Sunday is 6. With the methods of this class, we prepare a calendar for formatting.<\/span><\/p>\n<p><span style=\"font-weight: 400\">An instance of Calendar will have the following methods-<\/span><\/p>\n<h4>1. iterweekdays() &#8211; Days of week<\/h4>\n<p><span style=\"font-weight: 400\">This returns an iterator for the weekday numbers for an entire week. The first number this iterator returns is the number we set as the <\/span><i><span style=\"font-weight: 400\">firstweekday<\/span><\/i><span style=\"font-weight: 400\">.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import calendar as cd\r\n&gt;&gt;&gt; c=cd.Calendar(firstweekday=1)\r\n&gt;&gt;&gt; for i in c.iterweekdays():\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5<br \/>\n6<br \/>\n0<\/div>\n<h4>2. itermonthdates(year, month) &#8211; Dates of month<\/h4>\n<p><span style=\"font-weight: 400\">This returns an iterator for all days of the month and all days before or after it so we can get a complete week. Let\u2019s set the first weekday to be Monday.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; c=cd.Calendar(firstweekday=0)\r\n&gt;&gt;&gt; for i in c.itermonthdates(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2018-11-26<br \/>\n2018-11-27<br \/>\n2018-11-28<br \/>\n2018-11-29<br \/>\n2018-11-30<br \/>\n2018-12-01<br \/>\n2018-12-02<br \/>\n2018-12-03<br \/>\n2018-12-04<br \/>\n2018-12-05<br \/>\n2018-12-06<br \/>\n2018-12-07<br \/>\n2018-12-08<br \/>\n2018-12-09<br \/>\n2018-12-10<br \/>\n2018-12-11<br \/>\n2018-12-12<br \/>\n2018-12-13<br \/>\n2018-12-14<br \/>\n2018-12-15<br \/>\n2018-12-16<br \/>\n2018-12-17<br \/>\n2018-12-18<br \/>\n2018-12-19<br \/>\n2018-12-20<br \/>\n2018-12-21<br \/>\n2018-12-22<br \/>\n2018-12-23<br \/>\n2018-12-24<br \/>\n2018-12-25<br \/>\n2018-12-26<br \/>\n2018-12-27<br \/>\n2018-12-28<br \/>\n2018-12-29<br \/>\n2018-12-30<br \/>\n2018-12-31<br \/>\n2019-01-01<br \/>\n2019-01-02<br \/>\n2019-01-03<br \/>\n2019-01-04<br \/>\n2019-01-05<br \/>\n2019-01-06<\/div>\n<h4>3. itermonthdays(year,month) &#8211; Days of month<\/h4>\n<p><span style=\"font-weight: 400\">This gives us an iterator for the month as \u2018day of month\u2019. The days outside the month we specify return 0.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.itermonthdays(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">0<br \/>\n0<br \/>\n0<br \/>\n0<br \/>\n0<br \/>\n1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5<br \/>\n6<br \/>\n7<br \/>\n8<br \/>\n9<br \/>\n10<br \/>\n11<br \/>\n12<br \/>\n13<br \/>\n14<br \/>\n15<br \/>\n16<br \/>\n17<br \/>\n18<br \/>\n19<br \/>\n20<br \/>\n21<br \/>\n22<br \/>\n23<br \/>\n24<br \/>\n25<br \/>\n26<br \/>\n27<br \/>\n28<br \/>\n29<br \/>\n30<br \/>\n31<br \/>\n0<br \/>\n0<br \/>\n0<br \/>\n0<br \/>\n0<br \/>\n0<\/div>\n<p><span style=\"font-weight: 400\">Notice how the days from months November and January fade into a 0?<\/span><\/p>\n<h4>4. itermonthdays2(year,month) &#8211; Day of month, day of week<\/h4>\n<p><span style=\"font-weight: 400\">This is the same as itermonthdays(), but returns tuples of day of month and day of week.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.itermonthdays2(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(0, 0)<br \/>\n(0, 1)<br \/>\n(0, 2)<br \/>\n(0, 3)<br \/>\n(0, 4)<br \/>\n(1, 5)<br \/>\n(2, 6)<br \/>\n(3, 0)<br \/>\n(4, 1)<br \/>\n(5, 2)<br \/>\n(6, 3)<br \/>\n(7, 4)<br \/>\n(8, 5)<br \/>\n(9, 6)<br \/>\n(10, 0)<br \/>\n(11, 1)<br \/>\n(12, 2)<br \/>\n(13, 3)<br \/>\n(14, 4)<br \/>\n(15, 5)<br \/>\n(16, 6)<br \/>\n(17, 0)<br \/>\n(18, 1)<br \/>\n(19, 2)<br \/>\n(20, 3)<br \/>\n(21, 4)<br \/>\n(22, 5)<br \/>\n(23, 6)<br \/>\n(24, 0)<br \/>\n(25, 1)<br \/>\n(26, 2)<br \/>\n(27, 3)<br \/>\n(28, 4)<br \/>\n(29, 5)<br \/>\n(30, 6)<br \/>\n(31, 0)<br \/>\n(0, 1)<br \/>\n(0, 2)<br \/>\n(0, 3)<br \/>\n(0, 4)<br \/>\n(0, 5)<br \/>\n(0, 6)<\/div>\n<h4>5. itermonthdays3(year,month) &#8211; Year, month, day of month<\/h4>\n<p><span style=\"font-weight: 400\">This is like the previous two, but gives us a tuple of year, the month, and the day of the month. This is new in Python 3.7.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.itermonthdays3(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(2018, 11, 26)<br \/>\n(2018, 11, 27)<br \/>\n(2018, 11, 28)<br \/>\n(2018, 11, 29)<br \/>\n(2018, 11, 30)<br \/>\n(2018, 12, 1)<br \/>\n(2018, 12, 2)<br \/>\n(2018, 12, 3)<br \/>\n(2018, 12, 4)<br \/>\n(2018, 12, 5)<br \/>\n(2018, 12, 6)<br \/>\n(2018, 12, 7)<br \/>\n(2018, 12, 8)<br \/>\n(2018, 12, 9)<br \/>\n(2018, 12, 10)<br \/>\n(2018, 12, 11)<br \/>\n(2018, 12, 12)<br \/>\n(2018, 12, 13)<br \/>\n(2018, 12, 14)<br \/>\n(2018, 12, 15)<br \/>\n(2018, 12, 16)<br \/>\n(2018, 12, 17)<br \/>\n(2018, 12, 18)<br \/>\n(2018, 12, 19)<br \/>\n(2018, 12, 20)<br \/>\n(2018, 12, 21)<br \/>\n(2018, 12, 22)<br \/>\n(2018, 12, 23)<br \/>\n(2018, 12, 24)<br \/>\n(2018, 12, 25)<br \/>\n(2018, 12, 26)<br \/>\n(2018, 12, 27)<br \/>\n(2018, 12, 28)<br \/>\n(2018, 12, 29)<br \/>\n(2018, 12, 30)<br \/>\n(2018, 12, 31)<br \/>\n(2019, 1, 1)<br \/>\n(2019, 1, 2)<br \/>\n(2019, 1, 3)<br \/>\n(2019, 1, 4)<br \/>\n(2019, 1, 5)<br \/>\n(2019, 1, 6)<\/div>\n<h4>6. itermonthdays4(year, month) &#8211; Year, month, day of month, day of week<\/h4>\n<p><span style=\"font-weight: 400\">Like so far, this returns a tuple with year, month, day of month, and day of week. This is since Python 3.7.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.itermonthdays4(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(2018, 11, 26, 0)<br \/>\n(2018, 11, 27, 1)<br \/>\n(2018, 11, 28, 2)<br \/>\n(2018, 11, 29, 3)<br \/>\n(2018, 11, 30, 4)<br \/>\n(2018, 12, 1, 5)<br \/>\n(2018, 12, 2, 6)<br \/>\n(2018, 12, 3, 0)<br \/>\n(2018, 12, 4, 1)<br \/>\n(2018, 12, 5, 2)<br \/>\n(2018, 12, 6, 3)<br \/>\n(2018, 12, 7, 4)<br \/>\n(2018, 12, 8, 5)<br \/>\n(2018, 12, 9, 6)<br \/>\n(2018, 12, 10, 0)<br \/>\n(2018, 12, 11, 1)<br \/>\n(2018, 12, 12, 2)<br \/>\n(2018, 12, 13, 3)<br \/>\n(2018, 12, 14, 4)<br \/>\n(2018, 12, 15, 5)<br \/>\n(2018, 12, 16, 6)<br \/>\n(2018, 12, 17, 0)<br \/>\n(2018, 12, 18, 1)<br \/>\n(2018, 12, 19, 2)<br \/>\n(2018, 12, 20, 3)<br \/>\n(2018, 12, 21, 4)<br \/>\n(2018, 12, 22, 5)<br \/>\n<b>(<\/b>2018, 12, 23, 6)<br \/>\n(2018, 12, 24, 0)<br \/>\n(2018, 12, 25, 1)<br \/>\n(2018, 12, 26, 2)<br \/>\n(2018, 12, 27, 3)<br \/>\n(2018, 12, 28, 4)<br \/>\n(2018, 12, 29, 5)<br \/>\n(2018, 12, 30, 6)<br \/>\n(2018, 12, 31, 0)<br \/>\n(2019, 1, 1, 1)<br \/>\n(2019, 1, 2, 2)<br \/>\n(2019, 1, 3, 3)<br \/>\n(2019, 1, 4, 4)<br \/>\n(2019, 1, 5, 5)<br \/>\n(2019, 1, 6, 6)<\/div>\n<h4>7. monthdatescalendar(year,month) &#8211; List of weeks in month<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a list of full weeks in the month we want. Each week is a list of seven datetime.date objects.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.monthdatescalendar(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[datetime.date(2018, 11, 26), datetime.date(2018, 11, 27), datetime.date(2018, 11, 28), datetime.date(2018, 11, 29), datetime.date(2018, 11, 30), datetime.date(2018, 12, 1), datetime.date(2018, 12, 2)]<br \/>\n[datetime.date(2018, 12, 3), datetime.date(2018, 12, 4), datetime.date(2018, 12, 5), datetime.date(2018, 12, 6), datetime.date(2018, 12, 7), datetime.date(2018, 12, 8), datetime.date(2018, 12, 9)]<br \/>\n[datetime.date(2018, 12, 10), datetime.date(2018, 12, 11), datetime.date(2018, 12, 12), datetime.date(2018, 12, 13), datetime.date(2018, 12, 14), datetime.date(2018, 12, 15), datetime.date(2018, 12, 16)]<br \/>\n[datetime.date(2018, 12, 17), datetime.date(2018, 12, 18), datetime.date(2018, 12, 19), datetime.date(2018, 12, 20), datetime.date(2018, 12, 21), datetime.date(2018, 12, 22), datetime.date(2018, 12, 23)]<br \/>\n[datetime.date(2018, 12, 24), datetime.date(2018, 12, 25), datetime.date(2018, 12, 26), datetime.date(2018, 12, 27), datetime.date(2018, 12, 28), datetime.date(2018, 12, 29), datetime.date(2018, 12, 30)]<br \/>\n[datetime.date(2018, 12, 31), datetime.date(2019, 1, 1), datetime.date(2019, 1, 2), datetime.date(2019, 1, 3), datetime.date(2019, 1, 4), datetime.date(2019, 1, 5), datetime.date(2019, 1, 6)]<\/div>\n<p><span style=\"font-weight: 400\">To confirm this is correct, check the calendar for December 2018 with Monday as the first day:<\/span><br \/>\n<span style=\"font-weight: 400\">The weeks begin at 26, 3, 19, 17, 24, and 31.<\/span><\/p>\n<h4>8. monthdays2calendar(year,month) &#8211; List of days of the month and days of week in month<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a list of weeks with each week as seven tuples of day of month and day of the week.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.monthdays2calendar(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 5), (2, 6)]<br \/>\n[(3, 0), (4, 1), (5, 2), (6, 3), (7, 4), (8, 5), (9, 6)]<br \/>\n[(10, 0), (11, 1), (12, 2), (13, 3), (14, 4), (15, 5), (16, 6)]<br \/>\n[(17, 0), (18, 1), (19, 2), (20, 3), (21, 4), (22, 5), (23, 6)]<br \/>\n[(24, 0), (25, 1), (26, 2), (27, 3), (28, 4), (29, 5), (30, 6)]<br \/>\n[(31, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6)]<\/div>\n<p><span style=\"font-weight: 400\">Every week has week numbers 0 to 6 as the second value in the tuples and the first value is the day of month- 0 to 31 here.<\/span><\/p>\n<h4>9. monthdayscalendar(year,month) &#8211; List of day of month<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a list of weeks with each week as a list of day of month.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.monthdayscalendar(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[0, 0, 0, 0, 0, 1, 2]<br \/>\n[3, 4, 5, 6, 7, 8, 9]<br \/>\n[10, 11, 12, 13, 14, 15, 16]<br \/>\n[17, 18, 19, 20, 21, 22, 23]<br \/>\n[24, 25, 26, 27, 28, 29, 30]<br \/>\n[31, 0, 0, 0, 0, 0, 0]<\/div>\n<h4>10. yeardatescalendar(year,width=3) &#8211; List of row months<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a list of month rows. The <\/span><i><span style=\"font-weight: 400\">width<\/span><\/i><span style=\"font-weight: 400\"> parameter is to specify up to how many months we want in a month row, the default for which is 3. The days are datetime.date objects.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.yeardatescalendar(2018,2):\r\n        print(i)<\/pre>\n<p>&nbsp;<\/p>\n<h4>11. yeardays2calendar(year,width=3) &#8211; List of day of month and day of week<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a list of list of weeks as tuples of day of month and day of week.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.yeardays2calendar(2018,2):\r\n        print(i)<\/pre>\n<h4>12. yeardayscalendar(year,width=3) &#8211; List of day of month<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a list of weeks as day of month.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in c.yeardayscalendar(2018,2):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[[[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, 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, 0, 0, 0, 0]]]<br \/>\n[[[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, 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, 0, 0, 0, 0, 0, 0]]]<br \/>\n[[[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, 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, 0]]]<br \/>\n[[[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]], [[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]]]<br \/>\n[[[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]], [[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]]]<br \/>\n[[[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, 0, 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, 0]]]<\/div>\n<h3>Python TextCalendar Class<\/h3>\n<p><span style=\"font-weight: 400\">This class lets us generate plain text calendars. <\/span><\/p>\n<p><strong>Benefits of using a TextCalendar in Python:<\/strong><\/p>\n<ul>\n<li>By using the prmonth() function, the calendar can be shown by using just one line of code.<\/li>\n<li>You can easily change the size of the calendar, like adding more space between days or making the columns wider.<\/li>\n<li>The months and days can be shown in different languages, like Hindi, French, etc.<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">The constructor for this has the following syntax-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">class calendar.TextCalendar(firstweekday=0)<\/pre>\n<p><span style=\"font-weight: 400\">Take a look at its available methods-<\/span><\/p>\n<h4>1. formatmonth(theyear,themonth,[w=0,l=0]) &#8211; Multiline string of month<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a month\u2019s calendar as a multiline string. w is the width of centered date columns, l the number of lines for each week- both are optional parameters. We need the value of the <\/span><i><span style=\"font-weight: 400\">firstweekday<\/span><\/i><span style=\"font-weight: 400\"> for this to work.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t=cd.TextCalendar(0)\r\n&gt;&gt;&gt; t.formatmonth(2018,12)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216; \u00a0\u00a0December 2018\\nMo Tu We Th Fr Sa Su\\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01 2\\n 3 4 5 6 7 8 9\\n10 11 12 13 14 15 16\\n17 18 19 20 21 22 23\\n24 25 26 27 28 29 30\\n31\\n&#8217;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; print(t.formatmonth(2018,12))<\/pre>\n<p>&nbsp;<\/p>\n<h4>2. prmonth(theyear,themonth,[w=0,l=0]) &#8211; Print month calendar<\/h4>\n<p><span style=\"font-weight: 400\">What we printed last, we can also do with prmonth() instead.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t.prmonth(2018,12)<\/pre>\n<h4>3. formatyear(theyear,[w=2,l=1,c=6,m=3]) &#8211; Multiline string calendar<\/h4>\n<p><span style=\"font-weight: 400\">This returns an m-column calendar for the entire year as a multiline string. <\/span><span style=\"font-weight: 400\">Optional parameters- w for date column width, l for lines per week, c for number of spaces between month columns. <\/span><\/p>\n<p><span style=\"font-weight: 400\">For this to work, we need the <\/span><i><span style=\"font-weight: 400\">firstweekday<\/span><\/i><span style=\"font-weight: 400\">. The earliest year you can generate a calendar for depends on your platform.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; print(t.formatyear(2018,5)) #sets w=5 and m is 3 by default\r\n&gt;&gt;&gt; print(t.formatyear(2018,m=5))<\/pre>\n<p>&nbsp;<\/p>\n<h4>4. pryear(theyear,[w=2,l=1,c=6,m=3]) &#8211; Print year calendar<\/h4>\n<p><span style=\"font-weight: 400\">This prints the same thing as above.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t.pryear(2018,m=5)<\/pre>\n<h3>Python HTMLCalendar<\/h3>\n<p><span style=\"font-weight: 400\">Finally, let\u2019s talk about the class that lets us generate HTML Calendars in Python. The constructor for this has the following syntax:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">class calendar.HTMLCalendar(firstweekday=0)<\/pre>\n<p><span style=\"font-weight: 400\">An HTML Python Calendar instance has the following methods:<\/span><\/p>\n<h4>1. formatmonth(theyear,themonth,withyear=True) &#8211; HTML table for month calendar<\/h4>\n<p><span style=\"font-weight: 400\">This gives us the calendar for a month as an HTML table<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; h=cd.HTMLCalendar()\r\n&gt;&gt;&gt; print(h.formatmonth(2018,12))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&lt;table border=&#8221;0&#8243; cellpadding=&#8221;0&#8243; cellspacing=&#8221;0&#8243; class=&#8221;month&#8221;&gt;<br \/>\n&lt;tr&gt;&lt;th colspan=&#8221;7&#8243; class=&#8221;month&#8221;&gt;December 2018&lt;\/th&gt;&lt;\/tr&gt;<br \/>\n&lt;tr&gt;&lt;th class=&#8221;mon&#8221;&gt;Mon&lt;\/th&gt;&lt;th class=&#8221;tue&#8221;&gt;Tue&lt;\/th&gt;&lt;th class=&#8221;wed&#8221;&gt;Wed&lt;\/th&gt;&lt;th class=&#8221;thu&#8221;&gt;Thu&lt;\/th&gt;&lt;th class=&#8221;fri&#8221;&gt;Fri&lt;\/th&gt;&lt;th class=&#8221;sat&#8221;&gt;Sat&lt;\/th&gt;&lt;th class=&#8221;sun&#8221;&gt;Sun&lt;\/th&gt;&lt;\/tr&gt;<br \/>\n&lt;tr&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;sat&#8221;&gt;1&lt;\/td&gt;&lt;td class=&#8221;sun&#8221;&gt;2&lt;\/td&gt;&lt;\/tr&gt;<br \/>\n&lt;tr&gt;&lt;td class=&#8221;mon&#8221;&gt;3&lt;\/td&gt;&lt;td class=&#8221;tue&#8221;&gt;4&lt;\/td&gt;&lt;td class=&#8221;wed&#8221;&gt;5&lt;\/td&gt;&lt;td class=&#8221;thu&#8221;&gt;6&lt;\/td&gt;&lt;td class=&#8221;fri&#8221;&gt;7&lt;\/td&gt;&lt;td class=&#8221;sat&#8221;&gt;8&lt;\/td&gt;&lt;td class=&#8221;sun&#8221;&gt;9&lt;\/td&gt;&lt;\/tr&gt;<br \/>\n&lt;tr&gt;&lt;td class=&#8221;mon&#8221;&gt;10&lt;\/td&gt;&lt;td class=&#8221;tue&#8221;&gt;11&lt;\/td&gt;&lt;td class=&#8221;wed&#8221;&gt;12&lt;\/td&gt;&lt;td class=&#8221;thu&#8221;&gt;13&lt;\/td&gt;&lt;td class=&#8221;fri&#8221;&gt;14&lt;\/td&gt;&lt;td class=&#8221;sat&#8221;&gt;15&lt;\/td&gt;&lt;td class=&#8221;sun&#8221;&gt;16&lt;\/td&gt;&lt;\/tr&gt;<br \/>\n&lt;tr&gt;&lt;td class=&#8221;mon&#8221;&gt;17&lt;\/td&gt;&lt;td class=&#8221;tue&#8221;&gt;18&lt;\/td&gt;&lt;td class=&#8221;wed&#8221;&gt;19&lt;\/td&gt;&lt;td class=&#8221;thu&#8221;&gt;20&lt;\/td&gt;&lt;td class=&#8221;fri&#8221;&gt;21&lt;\/td&gt;&lt;td class=&#8221;sat&#8221;&gt;22&lt;\/td&gt;&lt;td class=&#8221;sun&#8221;&gt;23&lt;\/td&gt;&lt;\/tr&gt;<br \/>\n&lt;tr&gt;&lt;td class=&#8221;mon&#8221;&gt;24&lt;\/td&gt;&lt;td class=&#8221;tue&#8221;&gt;25&lt;\/td&gt;&lt;td class=&#8221;wed&#8221;&gt;26&lt;\/td&gt;&lt;td class=&#8221;thu&#8221;&gt;27&lt;\/td&gt;&lt;td class=&#8221;fri&#8221;&gt;28&lt;\/td&gt;&lt;td class=&#8221;sat&#8221;&gt;29&lt;\/td&gt;&lt;td class=&#8221;sun&#8221;&gt;30&lt;\/td&gt;&lt;\/tr&gt;<br \/>\n&lt;tr&gt;&lt;td class=&#8221;mon&#8221;&gt;31&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;td class=&#8221;noday&#8221;&gt;&amp;nbsp;&lt;\/td&gt;&lt;\/tr&gt;<br \/>\n&lt;\/table&gt;<\/div>\n<h4>2. formatyear(theyear,width=3) &#8211; HTML table for year calendar<\/h4>\n<p><span style=\"font-weight: 400\">This gives us an HTML table for an entire year\u2019s calendar. The width gives us the number of months in a row and defaults to 3.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; print(h.formatyear(2018,5))<\/pre>\n<h4>3. formatyearpage(theyear,width=3,css=\u2019calendar.css\u2019,encoding=None)<\/h4>\n<p><span style=\"font-weight: 400\">This gives us an entire year\u2019s calendar as an HTML page with the width defaulting to 3. If we use no cascading style sheet, we can put None there.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; print(h.formatyearpage(2018,css=None))<\/pre>\n<h3>Functions in the Python Calendar Module<\/h3>\n<p>So far, we have seen two subclasses of the Python Calendar Class- TextCalendar and HTMLCalendar. Now, let\u2019s take a look at all the functions we have with the Python Calendar Module.<\/p>\n<h4>1. calendar.setfirstweekday(weekday) &#8211; Set a day to begin the week at<\/h4>\n<p><span style=\"font-weight: 400\">This lets us set which day of the week to begin a week at. 0 is Monday and 6 is Sunday.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t.setfirstweekday(cd.SUNDAY)\r\n&gt;&gt;&gt; print(t.formatyear(2018,5))<\/pre>\n<h4>2. calendar.firstweekday &#8211; First day of the week<\/h4>\n<p><span style=\"font-weight: 400\">This gives us the first day of the week.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t.firstweekday<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">6<\/div>\n<h4>3. calendar.isleap(year) &#8211; Whether a year is leap year<\/h4>\n<p><span style=\"font-weight: 400\">This tells us whether a year is leap.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.isleap(2018)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<h4>4. calendar.leapdays(y1,y2) &#8211; Number of leap years in range<\/h4>\n<p><span style=\"font-weight: 400\">From year y1 to year y2, this gives us the number of leap years.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.leapdays(1995,2018)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">6<\/div>\n<h4>5. calendar.weekday(year,month,day) &#8211; Day of week<\/h4>\n<p><span style=\"font-weight: 400\">This returns the day of week, where 0 is Monday.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.weekday(2018,12,31)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">0<\/div>\n<h4>6. calendar.weekheader(n) &#8211; Abbreviated weekday names<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a header holding abbreviated weekday names. w is the width in characters for one weekday.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.weekheader(1)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;S M T W T F S&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.weekheader(2)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Su Mo Tu We Th Fr Sa&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.weekheader(3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Sun Mon Tue Wed Thu Fri Sat&#8217;<\/div>\n<h4>7. calendar.monthrange(year,month) &#8211; First day of month, number of days<\/h4>\n<p><span style=\"font-weight: 400\">This gives us the first day of the month and the number of days<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.monthrange(2018,12)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(5, 31)<\/div>\n<h4>8. calendar.monthcalendar(year,month) &#8211; Matrix of month calendar<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a matrix for a month\u2019s calendar.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in cd.monthcalendar(2018,12):\r\n        print(i)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[0, 0, 0, 0, 0, 0, 1]<br \/>\n[2, 3, 4, 5, 6, 7, 8]<br \/>\n[9, 10, 11, 12, 13, 14, 15]<br \/>\n[16, 17, 18, 19, 20, 21, 22]<br \/>\n[23, 24, 25, 26, 27, 28, 29]<br \/>\n[30, 31, 0, 0, 0, 0, 0]<\/div>\n<h4>9. calendar.prmonth(theyear,themonth,w=0,l=0) &#8211; Print multiline month<\/h4>\n<p><span style=\"font-weight: 400\">This prints the month that calendar.month gives us.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.prmonth(2018,12)<\/pre>\n<p>&nbsp;<\/p>\n<h4>10. calendar.month(theyear,themonth,w=0,l=0) &#8211; Multiline month string<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a month\u2019s calendar in a multiline string. For this, it uses the formatmonth() method from TextCalendar.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.month(2018,12)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216; \u00a0\u00a0December 2018\\nSu Mo Tu We Th Fr Sa\\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01\\n 2 3 4 5 6 7 8\\n 9 10 11 12 13 14 15\\n16 17 18 19 20 21 22\\n23 24 25 26 27 28 29\\n30 31\\n&#8217;<\/div>\n<h4>11. calendar.prcal(year,w=0,l=0,c=6,m=3) &#8211; Print year calendar<\/h4>\n<p><span style=\"font-weight: 400\">This prints the calendar of an entire year- one that calendar.calendar returns.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.prcal(2018)<\/pre>\n<h4>12. calendar.calendar(year,w=2,l=1,c=6,m=3) &#8211; Multiline string year calendar<\/h4>\n<p><span style=\"font-weight: 400\">This gives us a 3-column year calendar as a multiline string. For this, it uses the formatyear() method from TextCalendar.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; cd.calendar(2018)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02018\\n\\n January \u00a0\u00a0\u00a0\u00a0February March\\nSu Mo Tu We Th Fr Sa \u00a0\u00a0\u00a0\u00a0\u00a0Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa\\n 1 2 3 4 \u00a05 6 1 2 3 1 2 3\\n 7 8 9 10 11 12 13 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a04 5 6 7 8 9 10 4 5 6 7 8 9 10\\n14 15 16 17 18 19 20 11 12 13 14 15 16 17 \u00a0\u00a0\u00a0\u00a0\u00a011 12 13 14 15 16 17\\n21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24\\n28 29 30 31 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a025 26 27 28 25 26 27 28 29 30 31\\n\\n April May June\\nSu Mo Tu We Th Fr Sa \u00a0\u00a0\u00a0\u00a0\u00a0Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa\\n 1 2 3 4 5 6 7 1 2 3 4 5 1 2\\n 8 9 10 11 12 13 14 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a06 7 8 9 10 11 12 3 4 5 6 7 8 9\\n15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16\\n22 23 24 25 26 27 28 20 21 22 23 24 25 26 \u00a0\u00a0\u00a0\u00a0\u00a017 18 19 20 21 22 23\\n29 30 27 28 29 30 31 24 25 26 27 28 29 30\\n\\n July August September\\nSu Mo Tu We Th Fr Sa \u00a0\u00a0\u00a0\u00a0\u00a0Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa\\n 1 2 3 4 5 6 7 1 2 3 4 1\\n 8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8\\n15 16 17 18 19 20 21 \u00a0\u00a0\u00a0\u00a0\u00a012 13 14 15 16 17 18 9 10 11 12 13 14 15\\n22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22\\n29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29\\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a030\\n\\n October November December\\nSu Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa\\n 1 2 3 4 5 6 1 2 3 1\\n 7 8 9 10 11 12 13 4 \u00a05 6 7 8 9 10 2 3 4 5 6 7 8\\n14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15\\n21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22\\n28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29\\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a030 31\\n&#8217;<\/div>\n<h4>13. calendar.timegm(tuple) &#8211; Timestamp value from time tuple<\/h4>\n<p><span style=\"font-weight: 400\">This take a time tuple and returns a timestamp value with the epoch being 1970 and with a POSIX encoding. This is the inverse of time.gmtime().<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import time\r\n&gt;&gt;&gt; cd.timegm(time.gmtime(30000))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">30000<\/div>\n<p><span style=\"font-weight: 400\">So, this was all in the Python Calendar Module Tutorial. Hope you like our explanation.<\/span><\/p>\n<h3>Python Interview Questions on Calendar Module<\/h3>\n<ol>\n<li>What is the Calendar Module in Python?<\/li>\n<li>How to use the Python Calendar Module?<\/li>\n<li>How to print a whole year Calendar in Python?<\/li>\n<li>How to make a Calendar program in Python?<\/li>\n<li>How to import a Calendar Module in Python?<\/li>\n<\/ol>\n<h3><span style=\"font-weight: 400\">Conclusion<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Hence, in this Python Calendar tutorial, we saw the Calendar Module in Python. Moreover, we discussed the Python Calendar example to understand the module easily. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we look at TextCalendar and HTML Calendar in Python. At last, we learned the functions in the Python calendar Module. <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We took a brief look at the Python Calendar module when we talked about Python date and time. Let\u2019s take a deeper look at the Calendar Module in Python now. Moreover, we will talk&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":42729,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[2273,4969,10402,10403,10404,10405,10406,10585,10601,10888,14660,15859],"class_list":["post-29055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-calendar-class","tag-function-in-the-python-calendar-module","tag-python-calendar","tag-python-calendar-class","tag-python-calendar-example","tag-python-calendar-module","tag-python-calendar-scheduler","tag-python-html-calendar","tag-python-interactive-calendar","tag-python-textcalendar-class","tag-textcalendar-class","tag-what-is-python-calendar"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Calendar Module | Calendar Class &amp; HTML Calendar - DataFlair<\/title>\n<meta name=\"description\" content=\"Python calendar Module tutorial, What is Python Calendar,Calendar Class,Python HTML calendar,Python Calendar example,Python Calendar Scheduler\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-calendar-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Calendar Module | Calendar Class &amp; HTML Calendar - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python calendar Module tutorial, What is Python Calendar,Calendar Class,Python HTML calendar,Python Calendar example,Python Calendar Scheduler\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-calendar-module\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-11-23T04:20:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-23T10:08:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Calendar Module | Calendar Class &amp; HTML Calendar - DataFlair","description":"Python calendar Module tutorial, What is Python Calendar,Calendar Class,Python HTML calendar,Python Calendar example,Python Calendar Scheduler","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/","og_locale":"en_US","og_type":"article","og_title":"Python Calendar Module | Calendar Class &amp; HTML Calendar - DataFlair","og_description":"Python calendar Module tutorial, What is Python Calendar,Calendar Class,Python HTML calendar,Python Calendar example,Python Calendar Scheduler","og_url":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-11-23T04:20:00+00:00","article_modified_time":"2026-04-23T10:08:21+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Calendar Module | Calendar Class &amp; HTML Calendar","datePublished":"2018-11-23T04:20:00+00:00","dateModified":"2026-04-23T10:08:21+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/"},"wordCount":2419,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg","keywords":["Calendar Class","Function in the Python Calendar Module","Python calendar","Python Calendar Class","Python Calendar Example","Python calendar Module","Python Calendar Scheduler","Python HTML Calendar","Python Interactive Calendar","Python textCalendar Class","TextCalendar Class","What is Python Calendar"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-calendar-module\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/","url":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/","name":"Python Calendar Module | Calendar Class &amp; HTML Calendar - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg","datePublished":"2018-11-23T04:20:00+00:00","dateModified":"2026-04-23T10:08:21+00:00","description":"Python calendar Module tutorial, What is Python Calendar,Calendar Class,Python HTML calendar,Python Calendar example,Python Calendar Scheduler","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-calendar-module\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/11\/Python-Calendar-Module-01.jpg","width":1200,"height":628,"caption":"Python Calendar Module"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-calendar-module\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Calendar Module | Calendar Class &amp; HTML Calendar"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/29055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=29055"}],"version-history":[{"count":13,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/29055\/revisions"}],"predecessor-version":[{"id":147813,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/29055\/revisions\/147813"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/42729"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=29055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=29055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=29055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}