Python Days in a Month
The following code calculates the number of days in each month by importing the calendar module:
Example (Python 3.0+)
#!/usr/bin/python3
author by : www.runoob.com
import
calendar
monthRange
=
calendar
.
monthrange
(
2016
,
9
)
(
monthRange
)
The output of the code above is:
(3, 30)
The output is a tuple: the first element is the day of the week (0-6) of the first day of the queried month, and the second is the number of days in that month. The above example means that the first day of September 2016 was a Thursday and the month had 30 days in total.
Python3 Examples