"
This article is part of in the series
Published: Wednesday 5th April 2017
Last Updated: Tuesday 11th April 2017

Here's a fun thing about Python that you may or may not already be familiar with: it has a built-in calendar function you can use to display as many calendars as you like. When you import the function, you can use it to display a month of any year in standard calendar format (a month at the top, followed by 7 columns of days). Because it's a built-in function, it's actually relatively easy and simple to set up.

Like with any other built in function, to use it, first you need to import it, like this:

import calendar

So far so good. Next,  you'll need to set the year and the month of the month you'd like to display, using the variables yy and mm, respectively. So if you wanted to see the month February of 2016, you'd need to set your yy varible to 2016, and your mm variable to 2, like this:

yy = 2016
mm = 2

Remember: don't write out the name of the month you're trying to access. Use the numerical representation of the month as your variable value. So if you were trying to access the month of October,  you'd use the value 10. If you wanted to access April, it would be 4. For the year, make sure you write out the full year and not just the last two digits, as you might be wont to do because that's a common way to write out dates.

We're almost finished. To display the calendar, you'll have to print it using the following syntax:

print(calendar.month(yy, mm))

That's all the code it takes to display your month of choice in standard calendar form -- it's really pretty simple. Check below to see all the code together as one snippet.

import calendar

yy= 2016
mm = 2

print(calendar.month(yy, mm))

Play around with the dates to see how many months you can conjure up using Python's built-in calendar function!