Skip to main content

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 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:










Comments

Post a Comment

Popular posts from this blog

Fourer series formula

 Fourer series formula

DABASE MANAGEMENT SYSTEM QUESTIONS

 DABASE MANAGEMENT  SYSTEM SHORT QUESTIONS AND ANSWERS 1. What is database? A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world  and which is designed, built and populated with data for a specific purpose. 2. What is DBMS? It is a collection of programs that enables user to create and maintain a database. In other words it is general-purpose  software that provides the users with the processes of defining, constructing and manipulating the database for various  applications. 3. What is a Database system? The database and DBMS software together is called as Database system. 4. What are the advantages of DBMS? 1. Redundancy is controlled.  2. Unauthorised access is restricted.  3. Providing multiple user interfaces.  4. Enforcing integrity constraints.  5. Providing backup and recovery.  5. What are the disadvantage in File Processing System? 1. Data redundancy and incons...