Search code snippets, questions, articles...

Print whole month from calendar using python

To print the whole month with dates and days name using python, you can use the python module calendar and its calendar.month(year, month) method
import calendar

select_year = 2021
select_month = 11

print(calendar.month(select_year, select_month))

#    November 2021
# 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
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

In the code snippet, we want to print the calendar for the year 2021 and the month of November. First, we need to import the calendar module into our project. To do that we can use the below code.

import calendar

Next, we can use the calendar.month(year, month) method to print the whole month as shown in the above code.

Was this helpful?
0 Comments