Calendar in Python

Python has an inbuilt Calender Module to handle calendar related operations. Module calendar allows output calendars like the program and provides additional useful functions related to the calendar.

The functions and classes defined in this module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions. This matches the definition of the “proleptic Gregorian” calendar in Dershowitz and Reingold’s book “Calendrical Calculations”, where it’s the base calendar for all computations. Zero and negative years are interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is 2 BC, and so on.

By default, these calendars have Monday as the first day of the week, and Sunday as the last (the European convention).

Code

Example #1: Display Calendar of a Given Month.

#Display Calendar of a given month

import calendar

y=2000
m=2
print(calendar.month(y,m))

#Follow @code_snail

Output

image

Example #2: Display calendar of a given year.

# Display calendar of a given year

import calendar

print("Calender of 2021")
print(calendar.calendar(2021))

#Follow @code_snail

Output:

image 1

More functions here: https://docs.python.org/3/library/calendar.html

I hope you like this code. For more awesome code press the bell icon. Share it with your friends.

Also see,

Support CodeSnail

If you appreciate my work, or if it has helped you along your journey. It would mean a lot to me if you could write a message on my wall and share a cup of coffee (or tea) with me.

Buy Me A Coffee
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.

Leave a Comment