Google News
logo
Python Calendar
Python provides calendar module which provides many functions and methods to work on calendar. By default, calendar takes Monday as the first day of the week and Sunday as the last one. To change this, call calendar.setfirstweekday() function. A list of methods and function used is given below : 
Methods Description
prcal(year) Prints the whole calendar of the year.
firstweekday() Returns the first week day. It is by default 0 which specifies Monday
isleap(year) Returns a Boolean value i.e., true or false. True in case given year is leap else false.
monthcalendar(year,month) Returns the given month with each week as one list.
leapdays(year1,year2) Return number of leap days from year1 to year2
prmonth(year,month) Print the given month of the given year
prcal(year)
>>> import calendar
>>> calendar.prcal(2017)
Output :
Calendar
firstweekday()
>>> import calendar
>>> print (calendar.firstweekday())
0
>>> 
isleap(year)
>>> import calendar
>>> print (calendar.isleap(2017))
False
>>> 
monthcalendar(year,month)
>>> import calendar
>>> print (calendar.monthcalendar(2017,8))
[[0, 1, 2, 3, 4, 5, 6], 
[7, 8, 9, 10, 11, 12, 13], 
[14, 15, 16, 17, 18, 19, 20], 
[21, 22, 23, 24, 25, 26, 27], 
[28, 29, 30, 31, 0, 0, 0]]
>>> 
prmonth(year,month)
>>> import calendar
>>> print (calendar.prmonth(2017,8))
    August 2017
Mo Tu We Th Fr Sa Su
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
None
>>>