BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Print Calendar

Last Updated: June 6, 2018 by Chaitanya Singh | Filed Under: Python Examples

We can use the built-in function month() of Calendar module to print a Calendar in Python. The function month() requires two arguments to display a Calendar of given month, first argument is the year in four digits format for example, 2003, 1997, 2018 etc. and second is the month in two digit format, for example 01, 04, 12 etc.

Program to print Calendar in Python

This program prompts the user to enter the year and month and based on the input it calls the month() function which displays the Calendar of the given month for a given year.

# Program published on https://beginnersbook.com
# Python program to print Calendar using
# Python built-in function

import calendar

# Enter in format - 2018, 1997, 2003 etc.
year = int(input("Enter Year: "))

# Enter in format - 01, 06, 12 etc.
month = int(input("Enter Month: "))

# printing Calendar
print(calendar.month(year, month))

Output:

Enter Year: 2018
Enter Month: 06
     June 2018
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

Source Code in PyCharm IDE:
Python program to print Calendar

Related Python Examples:

  1. Python program to reverse a String using recursion
  2. Python program to check leap year
  3. Python program to check prime number
  4. Python program to add two matrices

Top Related Articles:

  1. Python Program to Check Vowel or Consonant
  2. Python Program to Check if a Number is Positive Negative or Zero
  3. Python program to reverse a String using Recursion
  4. Python Program to Convert Decimal to Hexadecimal
  5. Python Program to Convert Celsius To Fahrenheit and Vice Versa

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap