def is_leap(year): """判断year是否为闰年,闰年返回True,非闰年返回False""" if year % 4 == 0 and year % 100 != 0: return True if year % 400 == 0: return True else: return False def days_of_month(date_str): """根据输入的年月日,返回该月的天数""" tian = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] a = date_str[4:6] b = date_str[:4] if is_leap(int(b)): tian[1] = 29 return (tian[int(a) - 1])