Python ProgrammingPython Programming

Python get last Sunday of specific Month and Year

import calendar

month = calendar.monthcalendar(2021, 2)

last_sunday = max(month[-1][calendar.SUNDAY], month[-2][calendar.SUNDAY])
print(last_sunday)
Output
28