calendar Module
The calendar module provides functions for working with days of the week, month calendars, and leap years.
The calendar module provides functions for working with days of the week, month calendars, and leap years.
import calendar
from datetime import date
cal = calendar.month(2024, 6) # text calendar for June 2024
print(cal)
is_leap = calendar.isleap(2024) # True
weekday = date(2024, 6, 15).weekday() # 0=Mon, 5=Sat
day_name = calendar.day_name[weekday] # "Saturday"
_, last_day = calendar.monthrange(2024, 2) # 29 (leap year Feb)
monthrange() returns the weekday of the first day and the number of days in the month.