Python ProgrammingPython Programming

Get weekday of first day of the month and number of days in month, from specified year and month

##
# Python's program to weekday of first day of the month and
# number of days in month, for the specified year and month.

import calendar

print("Year:2002 - Month:2")
month_range = calendar.monthrange(2002, 2)
print("Weekday of first day of the month:", month_range[0])
print("Number of days in month:", month_range[1])
print()
print("Year:2010 - Month:5")
month_range = calendar.monthrange(2010, 5)
print("Weekday of first day of the month:", month_range[0])
print("Number of days in month:", month_range[1])

Sample output of above program.
C:\programs\time>pep8 --first example15.py

C:\programs\time>python example15.py
Year:2002 - Month:2
Weekday of first day of the month: 4
Number of days in month: 28

Year:2010 - Month:5
Weekday of first day of the month: 5
Number of days in month: 31

C:\programs\time>