In [1]:
import calendar
In [2]:
help(calendar.monthrange)
In [3]:
"""
This returns a tuple.
the first item in the tuple is the weekday that
the month starts on and the second item is the
number of days in the month.
"""
calendar.monthrange(2014,12)
Out[3]:
In [4]:
#select the second item in the tuple only
#i.e. the number of days in the month
calendar.monthrange(2014,12)[1]
Out[4]:
In [5]:
#another example, using November
calendar.monthrange(2014,11)[1]
Out[5]:
In [6]:
#another example, using October
calendar.monthrange(2014,10)[1]
Out[6]:
No comments:
Post a Comment