Open In App

Calendar in Python

Last Updated : 03 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Python has a built-in Python Calendar module to work with date-related tasks. Using the module, we can display a particular month as well as the whole calendar of a year. In this article, we will see how to print a calendar month and year using Python.

Calendar in Python Example

Input:
yy = 2023
mm = 4

Output:

Calendar in Python

Calendar of April 2023

Displaying a Calendar for a Month in Python

In the program below, we import the Python calendar module. The built-in function month() inside the module takes in the year and the month and displays the calendar for that month of the year.

Python3




# import module
import calendar
 
yy = 2023
mm = 4
 
# display the calendar
print(calendar.month(yy, mm))


Output:

Displaying a Calendar for a Month in Python

Calendar of April 2023

OR, you can directly run from the command line (CMD in Windows or TERMINAL in Linux ) for displaying a month of a year. Just write the following command:

python -m calendar 2023 4

Output:

Calendar of April 2023

Calendar of April 2023

Displaying Calendar of a given Year in Python

In the program below, we import the calendar module. The built-in Python calendar() function inside the module takes in the year and displays the calendar for that year.

Python3




# import module
import calendar
 
yy = 2017
 
# display the calendar
print(calendar.calendar(yy))


Output:

Displaying Calendar of a given Year in Python

Calendar of 2023

OR, you can directly run from the command line (CMD in Windows or TERMINAL in Linux ) for displaying a year:

python -m calendar 2023

Output:

Calendar of 2023

Calendar of 2023



Previous Article
Next Article

Similar Reads

Python program to print Calendar without calendar or datetime module
Given the month and year. The task is to show the calendar of that month and in the given year without using any module or pre-defined functions. Examples: Input : mm(1-12) :9 yy :2010 Output : September 2010 Su Mo Tu We Th Fr Sa 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Approach: In the program below
3 min read
Calendar Functions in Python | Set 1( calendar(), month(), isleap()...)
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). C/
5 min read
Python calendar module : formatmonth() method
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.TextCalendar(firstweekday=0) can be used to generate plain text
2 min read
Python calendar module | itermonthdays2() method
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. itermonthdays2() method is used to get an iterator for the month in the year s
2 min read
Python calendar module : iterweekdays() method
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. iterweekdays() method returns an iterator for the week day numbers that will b
1 min read
Python calendar module : itermonthdays() method
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. itermonthdays() method returns an iterator of a specified month and a year. Da
1 min read
Python calendar module : monthdatescalendar() method
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. monthdatescalendar() method in Python is used to get a list of the weeks in th
2 min read
Python calendar module : monthdays2calendar() method
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. monthdays2calendar() method in Python is used to get a list of the weeks in th
2 min read
Python calendar module | monthdayscalendar() method
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. monthdayscalendar() method in Python is used to get a list of the weeks in the
2 min read
Python calendar module : yeardatescalendar() method
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. yeardatescalendar() method in Python is used to get a list of the weeks in the
3 min read
Practice Tags :