python
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
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?
Similar Posts
- [Python] Use json.dumps() to pretty-print Python dicts
- Use separator in print() method of python
- Print DataFrame in pretty format in Terminal
- Install dependencies using pip from requirement.txt file in Python
- [Python] Using comprehension expression to convert list of dictionaries to nested dictionary
- [Python] Create a list of objects using class names
- [Python] Get nodeid, module, function name using Pytest request built-in fixture