python
21. How to Print Calendar in Python (Video in Khmer)
Learn how to print a calendar in Python with simple examples.
2026-10-27 ยท 2 min read
Hello friend! ๐ Python has a calendar module. Use it to print a month or a full year.
In this post, I show you easy calendar examples. ๐
๐๏ธ Print a Month
Import calendar, then use month(year, month).
import calendar
print(calendar.month(2025, 1))
Output:
January 2025
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
The month number start at 1. January is 1, December is 12.
๐ Print a Full Year
Use calendar() to print all months in a year.
import calendar
print(calendar.calendar(2025))
This print all 12 months. The result is long.
๐ Show a Month in One Line
Use monthcalendar() to get the dates as a list. Each inner list is one week. A 0 mean no date for that month.
import calendar
weeks = calendar.monthcalendar(2025, 1)
print(weeks[0])
Output:
[0, 0, 1, 2, 3, 4, 5]
The first day in each week is Monday by default.
โ Check a Leap Year
Use isleap() to check if a year is a leap year.
import calendar
print(calendar.isleap(2024)) # True
print(calendar.isleap(2025)) # False
๐ฅ Video: Print Calendar 2025 in Python (Khmer)
๐ก Tips
- Import the module with
import calendar. - Use
calendar.month(year, month)to print one month. - Use
calendar.calendar(year)to print the full year. - Month number go from
1to12. - Use
calendar.isleap(year)to check leap year. - In the default calendar, week start on Monday.
โ Any Question?
Tell us in comment below! ๐
#Python #Calendar #Date #LearnPython #Beginner