calendar.monthrange(year, month) has this feature.
calendar.monthrange(year, month) returns the tuple, and this tuple's
Therefore, to find out the total number of days, you can use it with calendar.monthrange(year, month)[1]
.
import calendar
print calendar.monthrange(2016,1) #(4,31)
print calendar.monthrange(2016,4) #(4,30)
print calendar.monthrange(2016,1)[1] #31
print calendar.monthrange(2016,4)[1] #30
© 2024 OneMinuteCode. All rights reserved.