Python Program to Print a Calendar
Beginner · Dates and times
This program prints the calendar of a month, laid out in weeks like a wall calendar, using Python's built-in calendar module. It also shows how many days the month has and which day of the week it starts on.
Program
October 2026
Mo Tu We Th Fr Sa Su
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
October 2026 has 31 days
It starts on a Thursday
Is 2026 a leap year? FalseHow it works
calendar.month(year, month)returns the whole month as a block of text, with the days of the week as columns starting from Monday.calendar.monthrange(year, month)returns two numbers: the weekday of the 1st (0 for Monday) and how many days the month has.calendar.month_nameandcalendar.day_nameturn those numbers into names such as October and Thursday.calendar.isleap(year)tells you whether February has 29 days that year.
Other ways to write it
Weeks starting on Sunday
October 2026
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31The default calendar starts each week on Monday; TextCalendar(calendar.SUNDAY) starts it on Sunday, like most calendars printed in India.
Drawing the month yourself
Mo Tu We Th Fr Sa Su
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31This is roughly what the calendar module does: leave a blank slot for each weekday before the 1st, then print the days and start a new row after every Sunday.
Try it yourself
Print the calendar for the whole year with print(calendar.calendar(2026)).
Edit the program above and press Run, or open it in the full editor to save it and share it. To watch it run line by line, open it in the visualizer.
Related programs
All Python programs · CBSE class 12 practical file · Python exercises