In this tutorial, we are going to learn how to print the calendar of month and year using the calendar module of Python. It's a straightforward thing in Python. We need year and month numbers. That's it. Show Let's see how to print a year calendar. Follow the below steps to print the year calendar.
ExampleSee the below code. Live Demo # importing the calendar module import calendar # initializing the year year = 2020 # printing the calendar print(calendar.calendar(year)) OutputIf you run the above code, you will get the following output. 2020 January February March Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 1 2 1 6 7 8 9 10 11 12 3 4 5 6 7 8 9 2 3 4 5 6 7 8 13 14 15 16 17 18 19 10 11 12 13 14 15 16 9 10 11 12 13 14 15 20 21 22 23 24 25 26 17 18 19 20 21 22 23 16 17 18 19 20 21 22 27 28 29 30 31 24 25 26 27 28 29 23 24 25 26 27 28 29 30 31 April May June Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 1 2 3 1 2 3 4 5 6 7 6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14 13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21 20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28 27 28 29 30 25 26 27 28 29 30 31 29 30 July August September Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 1 2 1 2 3 4 5 6 6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13 13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20 20 21 22 23 24 25 26 17 18 19 20 21 22 23 20 21 22 23 24 25 26 27 28 29 30 31 24 25 26 27 28 29 30 27 28 29 30 31 October November December Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 1 1 2 3 4 5 6 5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13 12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20 19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27 26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31 30 Let's see how to print a month calendar. Follow the below steps to print the month calendar.
ExampleSee the below code. Live Demo # importing the calendar module import calendar # initializing the year and month year = 2020 month = 1 # printing the calendar print(calendar.month(year, month)) OutputIf you execute the above program, you will get the following result. January 2020 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 ConclusionIf you have any doubts in the tutorial, mention them in the comment section.
Updated on 12-Feb-2020 12:21:27
How do I show a calendar in Python?It is simple in python programming to display calendar. To do so, you need to import the calendar module which comes with Python.. import calendar.. # Enter the month and year.. yy = int(input("Enter year: ")). mm = int(input("Enter month: ")). # display the calendar.. print(calendar. month(yy,mm)). What is the command used to print calendar in Python?Import the calendar module. Initialize the year number. Print the calendar using calendar. calendar(year) class.
How do I print a whole year calendar in Python?Source Code: import calendar //import the calendar module def printcalendar(yr): # printing calendar print(calendar. calendar(yr)) # driver program yr = 2019 printcalendar(yr) Output: The whole calendar year of 2019 will be displayed as the output.
What does month () do in Python?The month() method is used to get a month's calendar in a multi-line string using the formatmonth() of the TextCalendar class. Year for which the calendar should be generated. Month for which the calendar should be generated.
|