Write a Python program to get the number of days of a given month and year


The program starts by importing the monthrange function from the calendar module in the Python Standard Library. Two variables, year and month, are created and set to the values 2014 and 6, respectively.

The monthrange function is called with the year and month as arguments, which returns a tuple with two values: the first day of the week of the first day of the month (where Monday is 0 and Sunday is 6), and the number of days in the month. Finally, the result of the function call is printed using the print function.

Source Code

from calendar import monthrange
year = 2014
month = 6
print(monthrange(year, month))

Output

(6, 30)

Example Programs