dev.rean.me
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

Share:

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 1 to 12.
  • 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


๐Ÿ“š Related Post

โ† Back to python
Share: