VOOZH about

URL: https://www.geeksforgeeks.org/python/python-calendar-module-htmlcalendar-formatmonth-method/

⇱ Python calendar module | HTMLCalendar formatmonth() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python calendar module | HTMLCalendar formatmonth() method

Last Updated : 13 May, 2022

Calendar module allows to output calendars like program, and provides additional useful functions related to the calendar. Functions and classes defined in Calendar module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions. class calendar.HTMLCalendar(firstweekday=0) can be used to generate  HTML calendars.. formatmonth() method is one of the methods of HTMLCalendar instance. formatmonth() method in Python is used to get month’s calendar as an HTML table.

Syntax: formatmonth(year, month, withyear=True) 

Parameter: 

year: year of the calendar 

month: month of the calendar

withyear: [optional] If withyear is true the year will be included in the header, otherwise just the month name will be used. 

Returns: Return a month’s calendar.

Code #1: 

Output: 

  Code #2: With parameter width 

Output: 

  Code #3: Year will be included in the header. 

Output: 

Comment