Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Days in a Month

Python Days in a Month

Document Object Reference Manual Python3 Examples

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

)

print

(

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.

Document Object Reference Manual Python3 Examples