Python – Calendar Module



Python | Calendar Module

Python defines an inbuilt module calendar that handles operations related to the calendar.
The calendar module allows output calendars like the program and provides additional useful functions related to the calendar. Functions and classes defined in the Calendar module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions. By default, these calendars have Monday as the first day of the week, and Sunday as the last (the European convention).

Example #1: Display the Calendar of a given month.

# Python program to display calendar of
# given month of the year
  
# import module
import calendar
  
yy = 2017
mm = 11
  
# display the calendar
print(calendar.month(yy, mm))

Output:

 

Example #2: Display calendar of the given year.

# Python code to demonstrate the working of
# calendar() function to print calendar
  
# importing calendar module
# for calendar operations
import calendar
  
# using calendar to print calendar of year
# prints calendar of 2018
print ("The calendar of year 2018 is : ")
print (calendar.calendar(2018, 2, 1, 6))

Output:

class calendar.Calendar : 
The calendar class creates a Calendar object. A Calendar object provides several methods that can be used for preparing the calendar data for formatting. This class doesn’t do any formatting itself. This is the job of subclasses. Calendar class allows the calculations for various tasks based on date, month, and year.

Last Updated on November 13, 2021 by admin

Leave a Reply

Your email address will not be published. Required fields are marked *

Recommended Blogs