1from datetime import date, timedelta
2
3last_day_of_prev_month = date.today().replace(day=1) - timedelta(days=1)
4
5start_day_of_prev_month = date.today().replace(day=1) - timedelta(days=last_day_of_prev_month.day)
6
7# For printing results
8print("First day of prev month:", start_day_of_prev_month)
9print("Last day of prev month:", last_day_of_prev_month)
1>>import calendar
2>>year, month = 2016, 12
3>>calendar.monthrange(year, month)[1]
431
5