Use monthrange function of the calendar module. It will give both start and end date for a given year and month. See the examples mentioned below.
>>> import calendar>>> calendar.monthrange(2000,2)(1, 29)>>> calendar.monthrange(2000,2)[1]29>>> calendar.monthrange(2016,2)[1]29>>> calendar.monthrange(2015,2)[1]28>>> calendar.monthrange(2015,1)[1]31