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 2022 print ("The calendar of year 2022 is : ")
print (calendar .calendar(2022, 2, 1, 6))
Calendar Functions in Python
Python defines an inbuilt module “calendar” which handles operations related to the calendar.
Operations on the calendar :
1. calendar(year, w, l, c):- This function displays the year, the width of characters, no. of lines per week, and column separations.
2. firstweekday() :- This function returns the first week day number. By default 0 (Monday).
3. isleap (year):- This function checks if the year mentioned in the argument is a leap or not.
4. leapdays (year1, year2):- This function returns the number of leap days between the specified years in arguments.
5. weekday(year, month, date) :- This function returns the week day number(0 is Monday) of the date specified in its arguments.
calendar() method_______________________________________
The calendar() method is used to get a 3-column calendar for an entire year as a multi-line string using the formatyear() of the TextCalendar class.
Syntax
calendar(year, w=2, l=1, c=6, m=3)
Parameters:
Good
ReplyDelete👍🏻
Delete