Python

Python Data Analytics Libraries – Top 4

It is essential to consider the concept of Data Analytics before entering into Python libraries that assist the operation of Data Analytics.

What is Data Analytics?

Data Analysis is a sub-domain of the larger topic of Data Science and Machine Learning. Yes, it is essential to evaluate and clean the data before modeling it against various methods.

By analyzing the data, we imply that the data must be understood in terms of distribution, statistical analysis of measurement, and data visualization in order to provide a clear image of the data.

Data analysis comprises the following:

  • Data cleansing
  • Recognizing and understanding the distribution of data values
  • Data statistical analysis with relation to the mean, standard deviation, and so on.
  • Visualization of data values in relation to statistical measurements.
  • The data is being formatted for processing into the model.

Data Analytics Libraries in Python

Python provides a large number of libraries that support the concept of data analytics. Yes, Python has a number of modules for pre-processing and analyzing data values.

Among them, some of the top most used libraries are:

  • SciKit-Learn
  • Pandas
  • OpenCV
  • PyBrain

SciKit-Learn

This is a free software library for Machine Learning development in Python. David Cournapeau created it as a Google Summer of Code project in 2007, and it was first released in June 2007. Scikit-learn is built on top of other Python libraries such as NumPy, SciPy, Matplotlib, Pandas, and others, therefore it has full interoperability with them.

While Scikit-learn is mostly built-in Python, some fundamental algorithms have been developed in Cython to increase efficiency. Scikit-learn allows you to implement numerous Supervised and Unsupervised Machine Learning models such as

  • Classification
  • Regression
  • Support Vector Machines
  • Random Forests
  • Nearest Neighbors
  • Naive Bayes
  • Decision Trees
  • Clustering, and so on.

Pandas

This is a free Python data analysis and manipulation software library. It was developed as a community library project and was first made available in 2008. Pandas offer a variety of high-performance and user-friendly data structures and operations for manipulating data in the form of numerical tables and time series. Pandas also include a number of tools for reading and writing data between in-memory data structures and various file formats.

In a nutshell, it is ideal for quick and easy data manipulation, data aggregation, reading and writing data, and data visualization. Pandas can also read data from files such as CSV, Excel, and others, or from a SQL database, and generate a Python object known as a data frame. A data frame is made up of rows and columns and can be used to manipulate data using operations like join, merge, groupby, concatenate, and so on.

OpenCV

OpenCV is a massive open-source computer vision, machine learning, and image processing library. OpenCV is compatible with a wide range of programming languages, including Python, C++, and Java. It can analyse photos and videos to recognise items, faces, and even human handwriting. When it is paired with other libraries, such as Numpy, a highly optimised library for numerical operations, the number of weapons in your arsenal grows, as any operation that can be done in Numpy can be merged with OpenCV.

This OpenCV tutorial will teach you the fundamentals of image processing, such as operations on images and videos, through the use of a large collection of OpenCV programs and projects.

As a result, OpenCV supports the following–

  1. Facial recognition
  2. object identification
  3. tracking motion and mobility, and so on.

PyBrain

Pybrain is an open-source machine learning library in python. The library includes some simple training methods for networks, datasets, and trainers for training and testing the network.

Pybrain is defined as follows in its official documentation:

PyBrain is a Python Machine Learning Library that is modular. Its purpose is to provide flexible, user-friendly, yet strong algorithms for Machine Learning Tasks, as well as a range of predefined environments in which to test and compare your algorithms.

Python-Based Reinforcement Learning, Artificial Intelligence, and Neural Network Library is abbreviated as PyBrain. In fact, we invented the term first and then reverse-engineered this highly descriptive “Backronym.”

It supports a number of data analysis algorithms that may be used to improve data analysis and evaluate the results in a number of contexts.

 

 

Python Data Analytics Libraries – Top 4 Read More »

Python Data Science Libraries

Python is today’s most popular programming language. Python never ceases to amaze its users when it comes to solving data science tasks and challenges. Most data scientists already use Python programming on a daily basis. Python is an easy-to-learn, easy-to-debug, widely used, object-oriented, open-source, high-performance language, and it has many other advantages. Python has been designed with extraordinary Python libraries for data science that programmers use every day to solve problems.

Python in Data Science:

Because of its statistical analysis, data modeling, and readability, Python is one of the best programming languages for extracting value from this data.

Python is one of the best fits for data science for the following reasons–

  • Built-in libraries to support a variety of data science tasks.
  • Various development modules are available for use.
  • Excellent memory management abilities.
  • Algorithms for complex tasks processing

With the benefits listed above, Python can be used as a powerful tool to handle and solve data science problems.

Python Data Science Libraries

  1. NumPy
  2. TensorFlow
  3. SciPy
  4. Pandas
  5. Matplotlib
  6. Keras
  7. Seaborn
  8. Beautiful Soup
  9. PyTorch

  10. Scrapy

NumPy

It is a free Python software library that allows you to perform numerical computations on data in the form of large arrays and multi-dimensional matrices. These multidimensional matrices are the main objects in NumPy, where their dimensions are referred to as axes and the number of axes is referred to as a rank. NumPy also includes a variety of tools for working with these arrays, as well as high-level mathematical functions for manipulating this data using linear algebra, Fourier transforms, random number crunching, and so on. Adding, slicing, multiplying, flattening, reshaping, and indexing arrays are some of the basic array operations that NumPy can perform. Stacking arrays, splitting them into sections, broadcasting arrays, and other advanced functions are also available.

TensorFlow

TensorFlow is a high-performance numerical computation library with approximately 35,000 comments and a vibrant community of approximately 1,500 contributors. It is used in a variety of scientific fields. TensorFlow is essentially a framework for defining and running computations involving tensors, which are partially defined computational objects that produce a value.

TensorFlow  Features:

  • improved visualization of computational graphs
  • In neural machine learning, it reduces error by 50 to 60%.
  • Parallel computing is used to run complex models.
  • Google-backed seamless library management.
  • Quicker updates and more frequent new releases to keep you up to date on the latest features.

Applications:

  • Image and speech recognition
  • Text-based applications
  • Analysis of Time-series
  • Video recognition/detection

SciPy 

The Python SciPy library is largely based on the NumPy library. It performs the majority of the advanced computations related to data modeling. The SciPy library enables us to perform statistical data analysis, algebraic computations, algorithm optimization, and other tasks.

We can even perform parallel computations on it using SciPy. It includes functions for data science operations like regression, probability, and so on.

In a nutshell, the SciPy module can easily handle all advanced computations in statistics, modelling, and algebra.

Pandas

This is a free Python data analysis and manipulation software library. It was developed as a community library project and was first made available in 2008. Pandas offer a variety of high-performance and user-friendly data structures and operations for manipulating data in the form of numerical tables and time series. Pandas also include a number of tools for reading and writing data between in-memory data structures and various file formats.

In a nutshell, it is ideal for quick and easy data manipulation, data aggregation, reading and writing data, and data visualization. Pandas can also read data from files such as CSV, Excel, and others, or from a SQL database, and generate a Python object known as a data frame. A data frame is made up of rows and columns and can be used to manipulate data using operations like join, merge, groupby, concatenate, and so on.

Matplotlib 

Matplotlib’s visualizations are both powerful and wonderful. It’s a Python plotting library with over 26,000 comments on GitHub and a thriving community of over 700 contributors. It’s widely used for data visualization because of the graphs and plots it generates. It also includes an object-oriented API for embedding those plots into applications.

Matplotlib Features:

  • It can be used as a MATLAB replacement and has the advantage of being free and open source.
  • Supports dozens of backends and output types, so you can use it regardless of your operating system or output format preferences.
  • Pandas can be used as MATLAB API wrappers to drive MATLAB like a cleaner.
  • Low memory consumption and improved runtime performance

Applications:

  • Visualize the models’ 95 percent confidence intervals.
  • Visualize data distribution to gain instant insights.
  • Outlier detection with a scatter plot.
  • Correlation analysis of variables.

Keras

Keras is a Python-based deep learning API that runs on top of the TensorFlow machine learning platform. It was created with the goal of allowing for quick experimentation. “Being able to go from idea to result as quickly as possible is key to doing good research,” says Keras.

Many people prefer Keras over TensorFlow because it provides a much better “user experience.” Keras was developed in Python, making it easier for Python developers to understand. It is an easy-to-use library with a lot of power.

Seaborn

Seaborn is a Python library for data visualization that is based on Matplotlib. Data scientists can use Seaborn to create a variety of statistical models, such as heatmaps. Seaborn offers an impressive array of data visualization options, including time-series visualization, joint plots, violin diagrams, and many more. Seaborn uses semantic mapping and statistical aggregation to generate informative plots with deep insights.

Beautiful Soup

BeautifulSoup is a fantastic Python parsing module that supports web scraping from HTML and XML documents.

BeautifulSoup identifies encodings and handles HTML documents elegantly, even when they contain special characters. We can explore a parsed document and discover what we need, making it quick and easy to extract data from web pages.

PyTorch

PyTorch, is a Python-based scientific computing tool that makes use of the power of graphics processing units, PyTorch is a popular deep learning research platform that is designed to provide maximum flexibility and speed.

  • PyTorch is well-known for giving two of the most high-level features
  • tensor computations with significant GPU acceleration support,
  • construction of deep neural networks on a tape-based autograd system.

Scrapy

Scrapy is a must-have Python module for anyone interested in data scraping (extracting data from the screen). Scrapy allows you to improve the screen-scraping and web crawling processes. Scrapy is used by data scientists for data mining as well as automated testing. Scrapy is an open-source framework that many IT professionals use throughout the world to extract data from websites. Scrapy is developed in Python and is extremely portable, running on Linux, Windows, BSD, and Mac. Because of its great interactivity, many skilled developers favour Python for data analysis and scraping.

 

 

Python Data Science Libraries Read More »

Python Program for Changing Timezone

Product or infrastructure engineers are sometimes required to work on infrastructures located all over the world. They must work with machines in the United States, Asia, Europe, and the United Kingdom, among other locations. As a result, time zones play a significantly larger role in Python.

Several modules are kept in practically all programming languages due to the constant advancement of today’s computer languages. Python provides a time zone library called pytz that allows for real-time cross-platform time zone computations.

Installation of pytz Module:

Before going to the coding part, we will import the timezone library from the pytz module. This module can be installed using the pip command.

pip install pytz

Also, import datetime function from datetime module.

Program for Changing Timezone in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import timezone function from pytz module using the import keyword.
  • Import datetime function from datetime module using the import keyword.
  • Give some random date and time format and store it in a variable (The default format is YY-MM-DD HH:MM: SS).
  • Get the present time using the datetime.now() function.
  • Store it in another variable.
  • Convert the datetime into given string format using the strftime() function by passing the above given time format as an argument to it.
  • Store it in another variable.
  • Print the default date-time format.
  • Print the date-time in the above-given string format.
  • The Exit of the Program.

Below is the implementation:

# Import timezone function from pytz module using the import keyword.
from pytz import timezone
# Import datetime function from datetime module using the import keyword.
from datetime import datetime
# Give some random date and time format and store it in a variable (The default
# format is YY-MM-DD HH:MM:SS).
gvn_timeformt = '%Y-%m%d %H:%M:%S %Z%z'
# Get the present time using the datetime.now() function.
# Store it in another variable.
defalt_date_time = datetime.now()
# Convert the datetime into given string format using the strftime() function
# by passing the above given time format as an argument to it.
# Store it in another variable.
formtd_date_time = datetime.now().strftime(gvn_timeformt)
# Print the default date time format.
print("The default date time format = ", defalt_date_time)
# Print the date time in the above given string format
print("The date time in the above given string format = ", formtd_date_time)

Output:

The default date time format = 2021-12-06 19:33:22.854984 
The date time in the above given string format = 2021-1206 19:33:22
Conversion of current date-time to a different timezones

 

Approach:

  • Import timezone function from pytz module using the import keyword.
  • Import datetime function from datetime module using the import keyword.
  • Give some random date and time format and store it in a variable (The default format is YY-MM-DD HH:MM: SS).
  • Give the list of timezones as static input and store it in a variable.
  • Loop in the above-given timezones list using the for loop.
  • Inside the for loop, get the date-time by passing the place to the timezone() function and apply the strftime() function by passing the time format as an argument to it.
  • Print the date-time of given zones.
  • The Exit of the Program.

Below is the implementation:

# Import timezone function from pytz module using the import keyword.
from pytz import timezone
# Import datetime function from datetime module using the import keyword.
from datetime import datetime
# Give some random date and time format and store it in a variable
# (The default format is YY-MM-DD HH:MM: SS).
timeeformt = '%Y-%m%d %H:%M:%S %Z%z'
# Give the list of timezones as static input and store it in a variable.
t_zones_lst = ['Europe/London', 'US/Central',
               'Asia/Kolkata', 'UTC', 'Australia/Melbourne', ]
# Loop in the above-given timezones list using the for loop.
for t_zone in t_zones_lst:
    # Inside the for loop, get the date-time by passing the place to the
    # timezone() function and apply strftime() function by passing the time
    # format as argument to it.
    rslt_date_time = datetime.now(timezone(t_zone)).strftime(timeeformt)
    # Print the date-time of given zones.
    print(f"{t_zone} Date Time = {rslt_date_time}")

Output:

Europe/London Date Time = 2021-1208 16:36:11 GMT+0000 
US/Central Date Time = 2021-1208 10:36:11 CST-0600 
Asia/Kolkata Date Time = 2021-1208 22:06:11 IST+0530 
UTC Date Time = 2021-1208 16:36:11 UTC+0000 
Australia/Melbourne Date Time = 2021-1209 03:36:11 AEDT+1100

 

 

Python Program for Changing Timezone Read More »

Python Emoji Module with Examples

People nowadays communicate their emotions with emojis rather than extended lengths of text. Emojis have become an important part of our everyday communication with one another.

Emoji Module:

In Python, we may print the Emojis in a number of ways. They are:

printing Emojis with Unicodes, CLDR names, and the emoji module.

UsingUnicodes:

Every emoji is assigned a Unicode code.

Replace “+” with “000” in the list of Unicodes. For example, “U+1F600” will become “U0001F600,” with the Unicode prefixed by “\” and printed.

Emojis have a CLDR short name that can be utilized as well.

# Print the grinning face emoji
print("\U0001f600")
 
#  grinning squinting face emoji
print("\U0001F606")
print("\U0001F649")
# Print the rolling on the floor laughing emoji
print("\U0001F923")

Output:

????
????
????
????

Using CLDR short name:

# Print the grinning face emoji
print("\N{grinning face}")
 
# Print the slightly smiling face emoji
print("\N{slightly smiling face}")
 
# Print the winking face emoji
print("\N{winking face}")

Output:

????
????
????

Using emoji Module:

Before starting, install the emoji Module as shown below:

pip install emoji

Output:

Collecting emoji Downloading emoji-1.6.1.tar.gz (170 kB) 
|████████████████████████████████| 170 kB 15.6 MB/s Building wheels for 
collected packages: emoji Building wheel for emoji (setup.py) ... done 
Created wheel for emoji: filename=emoji-1.6.1-py3-none-any.whl size=169314 
sha256=5e835eb87674dd1171fd982e5e4c9490dce2d715db0e401221ff8e8902e4b4c1 Stored 
in directory: /root/.cache/pip/wheels/ea/5f/d3/03d313ddb3c2a1a427bb4690f1621eea
60fe6f2a30cc95940f Successfully built emoji Installing collected packages: emoji
Successfully installed emoji-1.6.1

emojize() Method:

The CLDR short name must be passed as a parameter to the emojize() method. The relevant emoji is then returned. In the CLDR short name, replace the spaces with underscores.

The emojize() method takes as a parameter the name of the emoji enclosed in a colon (:).

Example:

Approach:

  • Import emoji module using the import keyword.
  • Pass some random emoji name to the emojize() function and print it.
  • Similarly, print the other emojis.
  • The Exit of the Program.

Below is the implementation:

# Import emoji module using the import keyword.
import emoji
# Pass some random emoji name to the emojize() function and print it.
print(emoji.emojize(":thinking_face:"))
# Similarly print the other emoji's
print(emoji.emojize(":zany_face:"))
print(emoji.emojize(":zipper-mouth_face:"))

Output:

????
???? 
????

demojize() function:

It is a function that converts the emoji given into its CLDR short name.

Approach:

Below is the implementation:

# Import emoji module using the import keyword.
import emoji
# Pass some random emoji to the demojize() function to get the CLDR short name 
# of the emoji given and print it.
print(emoji.demojize("????"))
# Similarly print the other emoji's CLDR short name 
print(emoji.demojize("????"))
print(emoji.demojize("????"))

Output:

:thinking_face: 
:zany_face: 
:zipper-mouth_face:

Python Emoji Module with Examples Read More »

Python Wikipedia Module with Examples

Wikipedia Module:

Python’s Wikipedia module can be used to get a large amount of information from the well-known Wikipedia website.

We will begin by including the Wikipedia module in our system. If the importing command fails to work. Make sure you use the pip command to install the module.

Installation of wikipedia module:

pip install wikipedia

Output:

Collecting wikipedia Downloading wikipedia-1.4.0.tar.gz (27 kB) Requirement 
already satisfied: beautifulsoup4 in /usr/local/lib/python3.7/dist-packages 
(from wikipedia) (4.6.3) Requirement already satisfied: requests<3.0.0,>=2.0.0 
in /usr/local/lib/python3.7/dist-packages (from wikipedia) (2.23.0) Requirement 
already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages 
(from requests<3.0.0,>=2.0.0->wikipedia) (2.10) Requirement already satisfied: 
certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests<3.0
.0,>=2.0.0->wikipedia) (2021.10.8) Requirement already satisfied: chardet<4,>=3
.0.2 in /usr/local/lib/python3.7/dist-packages (from requests<3.0.0,>=2.0.0->
wikipedia) (3.0.4) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,
<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests<3.0.0,>
=2.0.0->wikipedia) (1.24.3) Building wheels for collected packages: wikipedia 
Building wheel for wikipedia (setup.py) ... done Created wheel for wikipedia: 
filename=wikipedia-1.4.0-py3-none-any.whl size=11696 sha256=77f5cc37acc194cd3b
7e74d9980194a3ef1a991797e43b89a69bc102dedafc4d Stored in directory: /root/.
cache/pip/wheels/15/93/6d/5b2c68b8a64c7a7a04947b4ed6d89fb557dcc6bc27d1d7f3ba 
Successfully built wikipedia Installing collected packages: wikipedia 
Successfully installed wikipedia-1.4.0

How to get the Data from the Wikipedia module?

To get Random Pages:

Choosing appropriate titles to search for might be a difficult process at times. Using the random method, one can obtain random titles.

If we require more than one random title, we can pass the number of pages as a parameter to the method. A list of titles is returned by the function.

# Import wikipedia module using the import keyword.
import wikipedia 
# Pass the number of pages as an argument to the random() function to get some 
# random titles and print it
print(wikipedia.random(pages=8))

Output:

['Gabriel P 6', 'Ambulyx charlesi', "Shooting at the 2014 Asian Games –
 Women's 10 metre air pistol team", 'Favolaschia', 'Akheem Gauntlett', 
'Jhorahat', 'Pavan Deshpande', 'Valerio Baldassari']

To get the summary:

Any tittle can be summarised using the summary method.

The summary method accepts a string as an argument that defines the title to search for. It returns a number of sentences for the specified title.

We can also add the number of sentences required as a parameter to limit the amount of stored data.

Approach:

  • Import wikipedia module using the import keyword.
  • Pass some random string, no of sentences as the argument to the summary() function.
  • Store it in a variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import wikipedia module using the import keyword.
import wikipedia
# Pass some random string, no of sentences as the argument to the summary() function
# Store it in a variable
sumry = wikipedia.summary('Ms. Dhoni-cricketer', sentences=40)
# Print the above result.
print(sumry)

Output:

M.S. Dhoni: The Untold Story is a 2016 Indian Hindi-language biographical sports
drama film written and directed by Neeraj Pandey. It is based on the life of
 former Test, ODI and T20I captain of the Indian national cricket team, Mahendra Singh Dhoni. The film stars the late Sushant Singh Rajput as Dhoni, along with Disha Patani, Kiara Advani, and Anupam Kher. The film chronicles the life of Dhoni from a young age through a series of life events. The idea of the biopic was put forward by Dhoni's manager, Arun Pandey, after encountering an incident at an airport after the 2011 Cricket World Cup Final. Development began two years later, with the consent of Dhoni. Neeraj Pandey was later approached to helm the film while he was working on Baby. Pandey recruited a number of people for researching into Dhoni's background and his life events. Dhoni eventually became a consultant on the film. The film was released on 30 September 2016 by Fox Star Studios and received the widest release ever for a Bollywood film across 61 countries.

To get the entire Wikipedia Page:

The page() function takes the title of the page as an argument and returns the whole Wikipedia Page.

The function returns a page object for the specified title. We can extract further information from the page object that was created.

Approach:

  • Import wikipedia module using the import keyword.
  • Pass some random title as an argument to the page() function to get the whole Wikipedia Page.
  • Store it in a variable.
  • Print the above-obtained page object.
  • Print the title of the given page using the original_title() function.
  • Print the categories of the given page using the categories() function.
  • Print the contents of the given page using the content() function.
  • The Exit of the Program.

Below is the implementation:

# Import wikipedia module using the import keyword.
import wikipedia
# Pass some random title as an argument to the page() function to get the whole
# Wikipedia Page.
# Store it in a variable.
gvn_page = wikipedia.page('Ms.Dhoni')
# Print the above-obtained page object.
print(gvn_page)
# Print the title of the given page using the original_title() function.
print("The title of the given page - \n", gvn_page.original_title)
print("\n")
# Print the categories of the given page using the categories() function.
print("The categories of the given page - ", gvn_page.categories)
print("\n")
# Print the contents of the given page using the content() function.
print("The contents of the given page -", gvn_page.content)

Output:

<WikipediaPage 'MS Dhoni'>
The title of the given page - 
 MS Dhoni


The categories of the given page -  ['1981 births', 'ACC Asian XI One Day International cricketers', 'All Wikipedia articles written in Indian English', 'All accuracy disputes', 'All articles covered by WikiProject Wikify', 'All articles lacking reliable references', 'All articles that are excessively detailed', 'All articles with specifically marked weasel-worded phrases', 'All articles with style issues', 'All articles with unsourced statements', 'All articles with vague or ambiguous time', 'All pages needing cleanup', 'All pages needing factual verification', 'Articles covered by WikiProject Wikify from December 2021', 'Articles lacking reliable references from December 2021', 'Articles lacking reliable references from November 2021', 'Articles lacking reliable references from October 2021', 'Articles needing more detailed references', 'Articles needing the year an event occurred from December 2021', 'Articles that may be too long from October 2021', 'Articles with FAST identifiers', 'Articles with GND identifiers', 'Articles with ISNI identifiers', 'Articles with LCCN identifiers', 'Articles with VIAF identifiers', 'Articles with WORLDCATID identifiers', 'Articles with disputed statements from October 2021', 'Articles with multiple maintenance issues', 'Articles with short description', 'Articles with specifically marked weasel-worded phrases from December 2021', 'Articles with unsourced statements from December 2021', 'Articles with unsourced statements from February 2019', 'Bihar cricketers', 'CS1 errors: bare URL', 'CS1 errors: missing title', 'CS1 maint: numeric names: authors list', 'CS1 maint: others', 'Wikipedia indefinitely semi-protected biographies of living people', 'Wikipedia introduction cleanup from December 2021']


The contents of the given page - Mahendra Singh Dhoni (born 7 July 1981), is a former international cricketer who captained the Indian national cricket team in limited-overs formats from 2007 to 2017 and in Test cricket from 2008 to 2014. He is currently the captain of Chennai Super Kings (CSK), a franchise based team of Indian Premier League. Having won the triple ICC limited-overs tournament as captain (inaugural 2007 ICC World Twenty20, 2011 ICC Cricket World Cup and 2013 ICC Champions Trophy) and bringing Indian cricket team to number one position in ICC test rankings in 2009, Dhoni is often considered as the greatest captain of Indian cricket team. Furthermore, he led CSK to win 2010, 2011, 2018 and 2021 edition of IPL, becoming second most successful IPL captain after Rohit Sharma.
Dhoni made his ODI debut on 23 December 2004 against Bangladesh, and played his first Test a year later against Sri Lanka. In 2007, he took over the ODI captaincy from Rahul Dravid. In test cricket his captaincy record was mixed, successfully leading India to series win against New Zealand (in 2009) and the Border-Gavaskar Trophy (home series in 2010 and 2013) against Australia while losing to Sri Lanka, Australia, England, and South Africa by big margins in away conditions. He announced his retirement from Tests on 30 December 2014 and captain of limited-overs game in 2017. Virat Kohli succeeded him as captain in both cases.
Dhoni announced his retirement from international cricket on 15 August 2020.


== Early life and background ==
Dhoni was born in Ranchi, Bihar (now in Jharkhand), and he hails from a Hindu Rajput family. His paternal village Lwali is in Jainti tehsil, Lamgara block of the Almora District of Uttarakhand. Dhoni's father is Pan Singh and his mother is Devaki Devi. His parents moved from Uttarakhand to Ranchi, Bihar where his father Pan Singh worked in junior management positions in MECON. He has a sister Jayanti Gupta and an elder brother Narendra Singh Dhoni.  His uncle, Pan Singh's brother, Ganapat Singh Dhauni lives in Lwali. Dhoni's uncle and cousins spell their surname as Dhauni but Mahendra Singh spells as Dhoni.Bhojpuri language is Dhoni's mother tongue.He is a fan of Adam Gilchrist, and his childhood idol in game of cricket was his former team-mate and former cricketer, Sachin Tendulkar. 


== Early career ==


=== Junior cricket in Bihar ===
In 1998, Dhoni was selected by Deval Sahay to play for the Central Coal Fields Limited (CCL) team. Till 1998 Dhoni, who was in class 12th in school, had played only school cricket and club cricket and no professional cricket. One of the famous episodes, when Dhoni used to play for CCL, was when Deval Sahay used to gift him Rs 50 for each six that he hit in Sheesh Mahal tournament cricket matches. Playing for CCL, he got a chance to bat up the order. He grabbed the opportunity and scored centuries and helped CCL move to the A division. tches, as East Zone lost all four matches and finished last in the tournament.


=== Bihar cricket team ===

Dhoni made his Ranji Trophy debut for Bihar in the 1999–2000 season, as an eighteen-year-old. He made a half century in his debut match scoring 68* in the second innings against Assam cricket team. Dhoni finished the season with 283 runs in 5 matches. Dhoni scored his maiden first-class century while playing for Bihar against Bengal in the 2000/01 season, this match ended as draw Apart from this century, his performance in the 2000/01 season did not include another score over fifty and in the 2001/02 season, he scored just five fifties in four Ranji matches.


=== Jharkhand cricket team ===
Dhoni's performance in the 2002–03 season included three half-centuries in the Ranji Trophy and a couple of half-centuries in the Deodhar Trophy, as he started gaining recognition for his lower-order contribution as well as hard-hitting batting style. In the 2003/04 season, Dhoni scored a century (128*) against Assam in the first match of the Ranji ODI tournament. Dhoni was part of the East Zone squad that won the Deodhar Trophy 2003–2004 season and contributed with 244 runs in 4 matches, including a century (114) against Central zone.y.


=== Start of ODI career ===
The Indian ODI team in the early 2000s saw Rahul Dravid as the wicket-keeper to ensure that the wicket-keeper spot didn't lack in batting talent. The team also saw the entry of wicket-keeper/batsmen from the junior ranks, with talents like Parthiv Patel and Dinesh Karthik (both India U-19 captains) named in the Test squads. With Dhoni making a mark in the India A squad, he was picked in the ODI squad for the Bangladesh tour in 2004/05. Dhoni did not have a great start to his ODI career, getting run out for a duck on debut. In spite of an average series against Bangladesh, Dhoni was picked for the Pakistan ODI series.


=== 2007 World Cup ===
Preparations for the 2007 Cricket World Cup improved as India recorded identical 3–1 victories over West Indies and Sri Lanka and Dhoni had averages in excess of 100 in both these series.India unexpectedly crashed out of the World Cup after losses to Bangladesh and Sri Lanka in the group stage. Dhoni was out for a duck in both these matches and scored just 29 runs in the tournament. After the loss to Bangladesh in 2007 Cricket World Cup, the house that Dhoni 

=== Rise through ranks ===
During the series between India and Australia in 2009, Dhoni hit an aggressive 124 runs in just 107 balls, in the second ODI, and a measured knock of 71 runs in 95 balls, along with Yuvraj Singh and saw India home by 6 wickets in the third ODI. Dhoni took his first and only wicket in international cricket on 30 September 2009. He bowled Travis Dowlin of the West Indies during a match in the 2009 ICC Champions Trophy.


=== 2015 World Cup ===
India's preparation, going into the tournament, looked poor as India failed badly in the Carlton Mid Triangular Series in Australia, failing to win a single match. Dhoni himself managed just 70 runs from three innings averaging 23.34.During the 2015 Cricket World Cup, Dhoni became the first Indian captain to win all group stage matches in such a tournament. India achieved wins against arch-rivals Pakistan, South Africa (whom they hadn't beaten before in a World Cup game), the UAE, West Indies, Ireland and Zimbabwe.

=== Stepping down as captain and thereafter ===
Dhoni stepped down as captain of India in the limited over formats in January 2017, just ahead of the ODI series at home against England. In the second game of the series, he scored 134 off 122 balls, that included a 256-run partnership for the fourth wicket along with Yuvraj Singh.

=== Retirement from international cricket ===
Dhoni announced his retirement from international cricket on 15 August 2020 on the day of India's 74th independence. He did so by posting a video on Instagram that contained pictures from both the best and the worst moments of his career with the song Mai Pal do Pal ka Shayar Hoon playing in the background. The video had been captioned as "Thanks a lot for ur love and support throughout.from 1929 hrs consider me as Retired".In November 2020, Dhoni was nominated for the ICC Men's ODI Cricketer of the Decade and ICC Spirit of Cricket Award of the Decade. Eventually, Dhoni was voted as winner of the ICC Spirit of Cricket Award of the Decade.


== Domestic career ==
On 23 December 2015, Delhi vs Jharkhand, in Vijay Hazare trophy Dhoni scored 70 (108) runs at 2nd quarter final at M. Chinnaswamy Stadium, Jharkhand lost that match.In 2017 Dhoni scored 129 (107) against Chhattisgarh at Eden gardens stadium in Kolkata in Vijay Hazare trophy, a one-day match tournament.He debuted in first class and List A Cricket in the season of 1999-2000.   In domestic cricket circuit he played for the teams such as Bihar, Jharkhand, 


== World Cup ==
Dhoni has captained India in two World Cups. Under his captaincy, India won the World Cup in 2011.


=== 2007 Cricket World Cup ===
Dhoni played his first ODI World Cup in 2007 in the Caribbean. 


=== 2011 Cricket World Cup ===

The bat used by Dhoni in the final match was sold for ₹72 Lac. The money goes to Sakshi Rawat Foundation, operated by Dhoni's wife Sakshi Rawat to help orphan children.


=== 2015 Cricket World Cup ===
For the 2015 World Cup held in Australia and New Zealand, Dhoni was named the captain of the 30-member squad by the BCCI in December 2014. Under his captaincy, India was able to go through to the semi-finals with ease, beating Bangladesh in the quarter-finals. 


== Indian Premier League ==

Dhoni was contracted by the Chennai Super Kings for US$1.5 million. This made him the most expensive player in the IPL for the first season auctions. Under his captaincy, Chennai Super Kings won the 2010, 2011, 2018 and the 2021 Indian Premier League titles and the 2010 and 2014 Champions League T20 titles.MS Dhoni became the first player to play 200 T20 matches for Chennai Super Kings. The former India captain is already on top of the list of most matches played in the Indian Premier League. Mahendra Singh Dhoni is also one of the only three captains to have won the Indian Premier League twice, with Chennai Super Kings.

== Playing style ==
Dhoni is a right-handed batsman and wicket-keeper. Dhoni is an unorthodox batsman in the sense that much of his batting technique defies the coaching manuals. Dhoni doesn't have a great footwork. He believes in muscling a full ball to Long-on, Long-off or Midwicket regions rather than driving it to the Cover region. Not only a great smasher of the full length balls, he also is a firm puller and hooker of the short balls, which makes it tough for the bowler to bowl to him. 

== Personal life ==

Dhoni is an introvert and shy person. He was a Ticket checker in South Eastern railway from September 2001 to July 2004 in Kharagpur.His ancestral village is Lwali, which is in Jaiti taluka of  Almora district of the Uttarakhand state. The village has population of 20 to 30 families.  His father Pan Singh Dhoni left the village in 1970 for employment. 


== International records ==


=== Test cricket ===
Under Dhoni's captaincy, India topped the Test cricket rankings for the first time, in 2009.

Dhoni has the most overseas Test defeats by an Indian captain, with 15.
Dhoni is the first Indian wicket-keeper to complete 4,000 Test runs.


=== T20I Cricket ===
Most matches as captain in T20Is(72)
Most matches in T20I history as both captain and wicket-keeper (72)
Most consecutive T20I innings without a duck (84).
Dhoni holds the record for playing the most T20I innings (76) and scored the most runs(1,153) before scoring a fifty.
Most dismissals as wicket-keeper in T20Is (87)
Most catches as wicket-keeper in T20Is (54)
Most stumpings as wicket-keeper in T20Is (33)
Most catches as wicket keeper in a T20I innings (5)

=== Dhoni Entertainment ===
In 2019, Dhoni Entertainment entered into a long-term business agreement with Banijay Asia to produce content in various genres. The first show developed was a documentary web series, titled Roar of The Lion, about the comeback of the Chennai Super Kings to lift the 2018 Indian Premier League starring MS Dhoni in the lead role. The web series is the biggest ever release through the platform of Hotstar Specials and started its online streaming from 20 March 2019.


=== Territorial Army ===

Dhoni holds a honorary rank of Lieutenant Colonel in the Parachute Regiment of the Indian Territorial Army (106 Para TA battalion). The honorary rank was presented to him by the Indian Army in 2011 for his service to the nation as a cricketer.After completing five parachute training jumps from Indian Army aircraft in the Agra training camp, he became a qualified paratrooper in 2015. In August 2019 he completed a two-week stint with the Territorial Army in Jammu and Kashmir.


== Awards and achievements ==


=== National honours ===
2018: Padma Bhushan, India's third-highest civilian award.
2009: Padma Shri, India's fourth-highest civilian award.
2007–08: Major Dhyanchand Khel Ratna award, India's highest honor given for achievement in sports.


=== Sporting honours ===
ICC ODI Player of the Year: 2008, 2009
ICC World ODI XI: 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014 (captain in 2009, 2011–2014)
Castrol Indian Cricketer of the Year: 2011
ICC Men's ODI team of the decade: 2011 - 2020 (captain and wicketkeeper)
ICC Men's T20I team of the decade: 2011 -2020 (captain and wicketkeeper)
ICC Spirit of the cricket award of the decade: 2011 - 2020


=== Other honours and awards ===
MTV Youth Icon of the Year: 2006
LG People's Choice Award: 2013
Honorary doctorate degree by De Montfort University in August 2011
CNN-News18 Indian of the Year: 2011
In 2019 Jharkhand Cricket association named their stadium's South stand after Dhoni.



== References ==


== External links ==
MS Dhoni at ESPNcricinfo
Mahendra Singh Dhoni at IndianKanoon

To get Data in different languages:

To obtain information in a different language, we will use the set_lang() function with the language specified as an argument.

Here “fr “- indicates the French language.

Approach:

  • Import wikipedia module using the import keyword.
  • Pass some random language(French) as an argument to the set_lang() function to obtain the data in the given language.
  • Pass some random string, no of sentences as the argument to the summary() function.
  • Store it in a variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import wikipedia module using the import keyword.
import wikipedia
# Pass some random language(French) as an argument to the set_lang() function to
# obtain the data in the given language.
wikipedia.set_lang("fr")
# Pass some random string, no of sentences as the argument to the summary() function.
# Store it in a variable.
sumry = wikipedia.summary('Doremon',sentences="10")
# Print the above result.
print(sumry)

Output:

Doraemon (ドラえもん) est une série de mangas japonais, créée par Fujiko Fujio, par la suite devenue un anime puis une franchise médiatique. La série se centre sur un chat-robot nommé Doraemon, ayant voyagé à travers le temps depuis le futur, afin d'aider un jeune garçon nommé Nobita Nobi (野比 のび太, Nobi Nobita). Le manga est initialement paru dans les marchés japonais en août 1969, lors de sa publication simultanée dans six différents magazines. Un total de 1 344 scénarios ont été créés pour la série, publiés par Shogakukan sous la branche Tentōmushi (てんとう虫), puis adaptés en quarante-cinq volumes. Les volumes sont conservés à la bibliothèque centrale de Takaoka, au Japon, la ville natale de Fujiko Fujio. Il s'agit par ailleurs de l'un des mangas les mieux vendus dans le monde, avec plus de 100 millions d'exemplaires, et de l'une des bandes dessinées les plus vendues au monde. La société américaine Turner Broadcasting System rachète les droits de l'anime Doraemon au milieu des années 1980 pour une parution en langue anglaise, mais annule sans explication sa programmation. La majeure partie des épisodes de Doraemon appartiennent au domaine de la comédie et des valeurs morales telles que l'honnêteté, la persévérance, le courage et le respect. De nombreux problèmes sociétaux et environnementaux sont souvent visités, comme l'abandon d'animaux, le réchauffement climatique, les espèces menacées, la déforestation, et la pollution. De nombreux sujets historiques comme la préhistoire et l'histoire du Japon sont également visités.

Python Wikipedia Module with Examples Read More »

Python Program for calendar leapdays() Method with Examples

Calendar Module:

The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely.

leapdays() Method:

calendar.leapdays() is a function in Python’s calendar module for creating simple text calendars.

The leapdays() method returns the number of leap years in a given range of years.
This function works for time spans of a century change.

Syntax:

leapdays(year1, year2)

Parameter Values: 

year1, year2: These are required. They are numbers. They are the years to get the number of leap years(range).

Return Value: The number of leap years in a given range is returned.

Examples:

Example1:

Input:

Given lower limit year = 2013
Given upper limit year = 2025

Output:

The number of leap years in a given range{ 2013 , 2025 } = 3

Example2:

Input:

Given lower limit year = 1999
Given upper limit year = 2002

Output:

The number of leap years in a given range{ 1999 , 2002 } = 1

Program for calendar leapdays() Method with Examples in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import calendar module using the import keyword.
  • Give the lower limit year as static input and store it in a variable.
  • Give the upper limit year as static input and store it in another variable.
  • Pass the given lower and upper limits as the arguments to the leapdays() function to get the number of leap years in a given range.
  • Store it in another variable.
  • Print the number of leap years in a given range.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the lower limit year as static input and store it in a variable.
gvn_yr1 = 2013
# Give the upper limit year as static input and store it in another variable.
gvn_yr2 = 2025
# Pass the given lower and upper limits as the arguments to the leapdays() function
# to get the number of leap years in a given range.
# Store it in another variable.
rslt = calendar.leapdays(gvn_yr1, gvn_yr2)
# Print the number of leap years in a given range.
print(
    "The number of leap years in a given range{", gvn_yr1, ",", gvn_yr2, "} = ", rslt)

Output:

The number of leap years in a given range{ 2013 , 2025 } = 3

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import calendar module using the import keyword.
  • Give the lower limit year as user input using the int(input()) function and store it in a variable.
  • Give the upper limit year as user input using the int(input()) function and store it in another variable.
  • Pass the given lower and upper limits as the arguments to the leapdays() function to get the number of leap years in a given range.
  • Store it in another variable.
  • Print the number of leap years in a given range.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the lower limit year as user input using the int(input()) function and store it in a variable.
gvn_yr1 = int(input("Enter some random year = "))
# Give the upper limit year as user input using the int(input()) function and store it another variable.
gvn_yr2 = int(input("Enter some random year = "))
# Pass the given lower and upper limits as the arguments to the leapdays() function
# to get the number of leap years in a given range.
# Store it in another variable.
rslt = calendar.leapdays(gvn_yr1, gvn_yr2)
# Print the number of leap years in a given range.
print(
    "The number of leap years in a given range{", gvn_yr1, ",", gvn_yr2, "} = ", rslt)

Output:

Enter some random year = 1999
Enter some random year = 2002
The number of leap years in a given range{ 1999 , 2002 } = 1

Python Program for calendar leapdays() Method with Examples Read More »

Python Program for calendar isleap() Method with Examples

Calendar Module:

The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely.

isleap() Method:

calendar.isleap() is a function in Python’s calendar module for creating simple text calendars.

The isleap() method produces a result. If the year is a leap year, True; otherwise, False.

A leap year is a year with one extra day added to bring the calendar year in synchronization with the astronomical or seasonal year.

Syntax:

isleap(year)

Parameter Values: 

year: This is required. It is a number. The Year to check if it’s a leap year or not.

Return Value:

If the year is a leap year, it returns True. Otherwise, False.

Examples:

Example1:

Input:

Given Year = 2012

Output:

Checking whether the given year 2012  is a leap or not =  True

Example2:

Input:

Given Year = 2017

Output:

Checking whether the given year 2017  is a leap or not =  False

Program for calendar isleap() Method with Examples in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import calendar module using the import keyword.
  • Give the year as static input and store it in a variable.
  • Pass the given year as an argument to the isleap() function to check whether the given year is a leap year or not.
  • Store it in another variable.
  • Print the result after checking whether the given year is a leap or not.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the year as static input and store it in a variable.
gvn_yr = 2012
# Pass the given year as an argument to the isleap() function to check whether
# the given year is a leap year or not.
# Store it in another variable.
rslt = calendar.isleap(gvn_yr)
# Print the result after checking whether the given year is a leap or not.
print("Checking whether the given year", gvn_yr, " is a leap or not = ", rslt)

Output:

Checking whether the given year 2012  is a leap or not =  True

The isleap() method’s operation is described below

Approach:

  • Import calendar module using the import keyword.
  • Give the year as static input and store it in a variable.
  • Pass the given year as an argument to the isleap() function to check whether the given year is a leap year or not.
  • Store it in another variable.
  • Check if the above result is equal to True using the if conditional statement.
  • If it is True, then Pass some random year, month, width, lines as arguments to the prmonth() method to print the specified month of the given leap year.
  • Else print “The given year is not a Leap Year”.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the year as static input and store it in a variable.
gvn_yr = 2012
# Pass the given year as an argument to the isleap() function to check whether
# the given year is a leap year or not.
# Store it in another variable.
rslt = calendar.isleap(gvn_yr)
# Check if the above result is equal to True using the if conditional statement.
if rslt == True:
    # If it is True, then Pass some random year, month, width, lines as
    # arguments to the prmonth() method to print the specified month of the
    # given leap year.
    calendar.prmonth(gvn_yr, 5, 3, 1)

# Else print "The given year is not a Leap Year".
else:
    print("The given year", gvn_yr, "is not a Leap Year")

Output:

          May 2012
Mon Tue Wed Thu Fri Sat Sun
      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

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import calendar module using the import keyword.
  • Give the year as user input using the int(input()) function and store it in a variable.
  • Pass the given year as an argument to the isleap() function to check whether the given year is a leap year or not.
  • Store it in another variable.
  • Print the result after checking whether the given year is a leap or not.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the year as user input using the int(input()) function and store it in a variable.
gvn_yr = int(input("Enter some random year = "))
# Pass the given year as an argument to the isleap() function to check whether
# the given year is a leap year or not.
# Store it in another variable.
rslt = calendar.isleap(gvn_yr)
# Print the result after checking whether the given year is a leap or not.
print("Checking whether the given year", gvn_yr, " is a leap or not = ", rslt)

Output:

Enter some random year = 2017
Checking whether the given year 2017 is a leap or not = False

The isleap() method’s operation is described below

Approach:

  • Import calendar module using the import keyword.
  • Give the year as user input using the int(input()) function and store it in a variable.
  • Pass the given year as an argument to the isleap() function to check whether the given year is a leap year or not.
  • Store it in another variable.
  • Check if the above result is equal to True using the if conditional statement.
  • If it is True, then Pass some random year, month, width, lines as arguments to the prmonth() method to print the specified month of the given leap year.
  • Else print “The given year is not a Leap Year”.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the year as user input using the int(input()) function and store it in a variable.
gvn_yr = int(input("Enter some random year = "))
# Pass the given year as an argument to the isleap() function to check whether
# the given year is a leap year or not.
# Store it in another variable.
rslt = calendar.isleap(gvn_yr)
# Check if the above result is equal to True using the if conditional statement.
if rslt == True:
    # If it is True, then Pass some random year, month, width, lines as
    # arguments to the prmonth() method to print the specified month of the
    # given leap year.
    calendar.prmonth(gvn_yr, 5, 3, 1)

# Else print "The given year is not a Leap Year".
else:
    print("The given year", gvn_yr, "is not a Leap Year")

Output:

Enter some random year = 2014
The given year 2014 is not a Leap Year

Python Program for calendar isleap() Method with Examples Read More »

Python Program for calendar firstweekday() Method with Examples

Calendar Module:

The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely.

firstweekday() Method:

calendar.firstweekday(weekday) is a function in Python’s calendar module for creating simple text calendars.

The firstweekday() method is used to retrieve the current weekday setting to begin each week.

Syntax:

firstweekday()

Parameter Values: This method has no parameters.

Return Value: None

Program for calendar firstweekday() Method with Examples in Python

Method #1: Using Built-in Functions (Static Input)

Example1:

Approach:

  • Import calendar module using the import keyword.
  • Call the firstweekday() function and print it.
  • Pass some random number as an argument to the setfirstweekday() function (to set the 3rd day as first weekday).
  • Print the first week day after setting to some random number by calling the firstweekday() function
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Call the firstweekday() function and print it.
print("The first weekday by default = ", calendar.firstweekday())
# Pass some random number as an argument to the setfirstweekday() function
# (to set the 3rd day as firstweekday)
calendar.setfirstweekday(3)
# Print the first week day after setting to some random number by calling the
# firstweekday() function
print("The first week day after setting to 3 = ", calendar.firstweekday())

Output:

The first weekday by default = 0
The first week day after setting to 3 = 3

Example2: Using the prmonth() function to demonstrate the operation of the firstweekday() method.

Approach:

  • Import calendar module using the import keyword.
  • Pass some random year, month, width, lines as argument to the prmonth() method for printing the calendar for specified year.
  • Set the first week day number using the setfirstweekday() method.
  • Verify the changed day using the firstweekday() method and print it.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Pass some random year, month, width, lines as argument to the prmonth() method
# for printing the calendar for specified year.
print("The calendar of May 2005 : ")
calendar.prmonth(2005, 5, 3, 1)
# Set the first week day number using the setfirstweekday() method.
calendar.setfirstweekday(3)
print("\r")
# Verify the changed day using the firstweekday() method and print it.
print("The changed first week day digit = ", end="")
print(calendar.firstweekday())

Output:

The calendar of May 2005 : 
          May 2005
Mon Tue Wed Thu Fri Sat Sun
                          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

The changed first week day digit = 3

Python Program for calendar firstweekday() Method with Examples Read More »

Python Program for calendar setfirstweekday() Method with Examples

Calendar Module:

The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely.

setfirstweekday() Method:

calendar.setfirstweekday(weekday) is a function in Python’s calendar module for creating simple text calendars.

The setfirstweekday() method sets the weekday (0 is Monday, 6 is Sunday) to start each week.
The values MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, and SUNDAY are provided for convenience.

Syntax:

setfirstweekday()

Parameter Values: This method has no parameters.

Return Value: None

Program for calendar setfirstweekday() Method with Examples in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import calendar module using the import keyword.
  • Set the day as SUNDAY, and pass it as an argument to the setfirstweekday() function.
  • Store it in a variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Set the day as SUNDAY, and pass it as an argument to the setfirstweekday() function
# Store it in a variable.
rslt_calndr = calendar.setfirstweekday(calendar.SUNDAY)
# Print the above result.
print(rslt_calndr)

Output:

None

Using the prmonth() function to demonstrate the operation of the setfirstweekday() method.

Reference : Python Program for calendar prmonth() Method with Examples

Approach:

  • Import calendar module using the import keyword.
  • Pass some random year, month, width, lines as argument to the prmonth() method.
  • Set the first week day number using the setfirstweekday() method.
  • Verify the changed day using the firstweekday() method and print it.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Pass some random year, month, width, lines as argument to the prmonth() method
print("The calendar of May 2005 : ")
calendar.prmonth(2005, 5, 3, 1)
# Set the first week day number using the setfirstweekday() method.
calendar.setfirstweekday(3)
print("\r")
# Verify the changed day using the firstweekday() method and print it.
print("The changed first week day digit = ", end="")
print(calendar.firstweekday())

Output:

The calendar of May 2005 : 
          May 2005
Mon Tue Wed Thu Fri Sat Sun
                          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

The changed first week day digit = 3

Python Program for calendar setfirstweekday() Method with Examples Read More »

Python Program for HTMLCalendar formatyearpage() Method with Examples

Calendar Module:

The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely.

HTMLCalendar formatyearpage() Method:

In Python, the formatyearpage() function is used to obtain the year’s calendar as a complete HTML page.

To generate HTML calendars, class calendar.HTMLCalendar(firstweekday=0) can be used. The formatyearpage() method is one of the HTMLCalendar instance methods.

Syntax:

formatyearpage(year, width=3, css=’calendar.css’, encoding=None)

Parameter Values:

year: This is required. It is a number. It is the year for which the calendar should be created.

width: Specifies the width of the date column. 3 is the default value.

css: This is optional. The name of the CSS that will be used.

encoding: This is optional. It specifies the encoding that should be used for the output.

Return Value: An HTML page for the whole year is returned.

It Depends on the first weekday as specified in the constructor or set by the setfirstweekday() method.

Program for HTMLCalendar formatyearpage() Method with Examples in Python

 

Method #1: Using Built-in Functions (Static Input)

Example1:

Approach:

  • Import calendar module using the import keyword.
  • Give the year as static input and store it in a variable.
  • Call the HTMLCalendar() function by setting firstweekday=0 and store it in another variable.
  • Apply formatyearpage() method to the above text calendar by passing the given year as an argument and store it in another variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the year as static input and store it in a variable.
gvn_yr = 2015
# Call the HTMLCalendar() function by setting firstweekday=0 and store it in
# another variable.
txt_calndr = calendar.HTMLCalendar(firstweekday=0)
# Apply formatyearpage() method to the above text calendar by passing the given year,
# as an argument and store it in another variable.
rslt = txt_calndr.formatyearpage(gvn_yr)
# Print the above result.
print(rslt)

Output:

b'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n
<html>
   \n
   <head>
      \n
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      \n
      <link rel="stylesheet" type="text/css" href="calendar.css" />
      \n
      <title>Calendar for 2015</title>
      \n
   </head>
   \n
   <body>
      \n
      <table border="0" cellpadding="0" cellspacing="0" class="year">
         \n
         <tr>
            <th colspan="3" class="year">2015</th>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">January</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="thu">1</td>
                     <td class="fri">2</td>
                     <td class="sat">3</td>
                     <td class="sun">4</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">5</td>
                     <td class="tue">6</td>
                     <td class="wed">7</td>
                     <td class="thu">8</td>
                     <td class="fri">9</td>
                     <td class="sat">10</td>
                     <td class="sun">11</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">12</td>
                     <td class="tue">13</td>
                     <td class="wed">14</td>
                     <td class="thu">15</td>
                     <td class="fri">16</td>
                     <td class="sat">17</td>
                     <td class="sun">18</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">19</td>
                     <td class="tue">20</td>
                     <td class="wed">21</td>
                     <td class="thu">22</td>
                     <td class="fri">23</td>
                     <td class="sat">24</td>
                     <td class="sun">25</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">26</td>
                     <td class="tue">27</td>
                     <td class="wed">28</td>
                     <td class="thu">29</td>
                     <td class="fri">30</td>
                     <td class="sat">31</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">February</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sun">1</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">2</td>
                     <td class="tue">3</td>
                     <td class="wed">4</td>
                     <td class="thu">5</td>
                     <td class="fri">6</td>
                     <td class="sat">7</td>
                     <td class="sun">8</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">9</td>
                     <td class="tue">10</td>
                     <td class="wed">11</td>
                     <td class="thu">12</td>
                     <td class="fri">13</td>
                     <td class="sat">14</td>
                     <td class="sun">15</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">16</td>
                     <td class="tue">17</td>
                     <td class="wed">18</td>
                     <td class="thu">19</td>
                     <td class="fri">20</td>
                     <td class="sat">21</td>
                     <td class="sun">22</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">23</td>
                     <td class="tue">24</td>
                     <td class="wed">25</td>
                     <td class="thu">26</td>
                     <td class="fri">27</td>
                     <td class="sat">28</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">March</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sun">1</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">2</td>
                     <td class="tue">3</td>
                     <td class="wed">4</td>
                     <td class="thu">5</td>
                     <td class="fri">6</td>
                     <td class="sat">7</td>
                     <td class="sun">8</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">9</td>
                     <td class="tue">10</td>
                     <td class="wed">11</td>
                     <td class="thu">12</td>
                     <td class="fri">13</td>
                     <td class="sat">14</td>
                     <td class="sun">15</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">16</td>
                     <td class="tue">17</td>
                     <td class="wed">18</td>
                     <td class="thu">19</td>
                     <td class="fri">20</td>
                     <td class="sat">21</td>
                     <td class="sun">22</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">23</td>
                     <td class="tue">24</td>
                     <td class="wed">25</td>
                     <td class="thu">26</td>
                     <td class="fri">27</td>
                     <td class="sat">28</td>
                     <td class="sun">29</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">30</td>
                     <td class="tue">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">April</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="wed">1</td>
                     <td class="thu">2</td>
                     <td class="fri">3</td>
                     <td class="sat">4</td>
                     <td class="sun">5</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">6</td>
                     <td class="tue">7</td>
                     <td class="wed">8</td>
                     <td class="thu">9</td>
                     <td class="fri">10</td>
                     <td class="sat">11</td>
                     <td class="sun">12</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">13</td>
                     <td class="tue">14</td>
                     <td class="wed">15</td>
                     <td class="thu">16</td>
                     <td class="fri">17</td>
                     <td class="sat">18</td>
                     <td class="sun">19</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">20</td>
                     <td class="tue">21</td>
                     <td class="wed">22</td>
                     <td class="thu">23</td>
                     <td class="fri">24</td>
                     <td class="sat">25</td>
                     <td class="sun">26</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">27</td>
                     <td class="tue">28</td>
                     <td class="wed">29</td>
                     <td class="thu">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">May</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="fri">1</td>
                     <td class="sat">2</td>
                     <td class="sun">3</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">4</td>
                     <td class="tue">5</td>
                     <td class="wed">6</td>
                     <td class="thu">7</td>
                     <td class="fri">8</td>
                     <td class="sat">9</td>
                     <td class="sun">10</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">11</td>
                     <td class="tue">12</td>
                     <td class="wed">13</td>
                     <td class="thu">14</td>
                     <td class="fri">15</td>
                     <td class="sat">16</td>
                     <td class="sun">17</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">18</td>
                     <td class="tue">19</td>
                     <td class="wed">20</td>
                     <td class="thu">21</td>
                     <td class="fri">22</td>
                     <td class="sat">23</td>
                     <td class="sun">24</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">25</td>
                     <td class="tue">26</td>
                     <td class="wed">27</td>
                     <td class="thu">28</td>
                     <td class="fri">29</td>
                     <td class="sat">30</td>
                     <td class="sun">31</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">June</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">1</td>
                     <td class="tue">2</td>
                     <td class="wed">3</td>
                     <td class="thu">4</td>
                     <td class="fri">5</td>
                     <td class="sat">6</td>
                     <td class="sun">7</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">8</td>
                     <td class="tue">9</td>
                     <td class="wed">10</td>
                     <td class="thu">11</td>
                     <td class="fri">12</td>
                     <td class="sat">13</td>
                     <td class="sun">14</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">15</td>
                     <td class="tue">16</td>
                     <td class="wed">17</td>
                     <td class="thu">18</td>
                     <td class="fri">19</td>
                     <td class="sat">20</td>
                     <td class="sun">21</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">22</td>
                     <td class="tue">23</td>
                     <td class="wed">24</td>
                     <td class="thu">25</td>
                     <td class="fri">26</td>
                     <td class="sat">27</td>
                     <td class="sun">28</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">29</td>
                     <td class="tue">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">July</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="wed">1</td>
                     <td class="thu">2</td>
                     <td class="fri">3</td>
                     <td class="sat">4</td>
                     <td class="sun">5</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">6</td>
                     <td class="tue">7</td>
                     <td class="wed">8</td>
                     <td class="thu">9</td>
                     <td class="fri">10</td>
                     <td class="sat">11</td>
                     <td class="sun">12</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">13</td>
                     <td class="tue">14</td>
                     <td class="wed">15</td>
                     <td class="thu">16</td>
                     <td class="fri">17</td>
                     <td class="sat">18</td>
                     <td class="sun">19</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">20</td>
                     <td class="tue">21</td>
                     <td class="wed">22</td>
                     <td class="thu">23</td>
                     <td class="fri">24</td>
                     <td class="sat">25</td>
                     <td class="sun">26</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">27</td>
                     <td class="tue">28</td>
                     <td class="wed">29</td>
                     <td class="thu">30</td>
                     <td class="fri">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">August</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sat">1</td>
                     <td class="sun">2</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">3</td>
                     <td class="tue">4</td>
                     <td class="wed">5</td>
                     <td class="thu">6</td>
                     <td class="fri">7</td>
                     <td class="sat">8</td>
                     <td class="sun">9</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">10</td>
                     <td class="tue">11</td>
                     <td class="wed">12</td>
                     <td class="thu">13</td>
                     <td class="fri">14</td>
                     <td class="sat">15</td>
                     <td class="sun">16</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">17</td>
                     <td class="tue">18</td>
                     <td class="wed">19</td>
                     <td class="thu">20</td>
                     <td class="fri">21</td>
                     <td class="sat">22</td>
                     <td class="sun">23</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">24</td>
                     <td class="tue">25</td>
                     <td class="wed">26</td>
                     <td class="thu">27</td>
                     <td class="fri">28</td>
                     <td class="sat">29</td>
                     <td class="sun">30</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">September</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="tue">1</td>
                     <td class="wed">2</td>
                     <td class="thu">3</td>
                     <td class="fri">4</td>
                     <td class="sat">5</td>
                     <td class="sun">6</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">7</td>
                     <td class="tue">8</td>
                     <td class="wed">9</td>
                     <td class="thu">10</td>
                     <td class="fri">11</td>
                     <td class="sat">12</td>
                     <td class="sun">13</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">14</td>
                     <td class="tue">15</td>
                     <td class="wed">16</td>
                     <td class="thu">17</td>
                     <td class="fri">18</td>
                     <td class="sat">19</td>
                     <td class="sun">20</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">21</td>
                     <td class="tue">22</td>
                     <td class="wed">23</td>
                     <td class="thu">24</td>
                     <td class="fri">25</td>
                     <td class="sat">26</td>
                     <td class="sun">27</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">28</td>
                     <td class="tue">29</td>
                     <td class="wed">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">October</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="thu">1</td>
                     <td class="fri">2</td>
                     <td class="sat">3</td>
                     <td class="sun">4</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">5</td>
                     <td class="tue">6</td>
                     <td class="wed">7</td>
                     <td class="thu">8</td>
                     <td class="fri">9</td>
                     <td class="sat">10</td>
                     <td class="sun">11</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">12</td>
                     <td class="tue">13</td>
                     <td class="wed">14</td>
                     <td class="thu">15</td>
                     <td class="fri">16</td>
                     <td class="sat">17</td>
                     <td class="sun">18</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">19</td>
                     <td class="tue">20</td>
                     <td class="wed">21</td>
                     <td class="thu">22</td>
                     <td class="fri">23</td>
                     <td class="sat">24</td>
                     <td class="sun">25</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">26</td>
                     <td class="tue">27</td>
                     <td class="wed">28</td>
                     <td class="thu">29</td>
                     <td class="fri">30</td>
                     <td class="sat">31</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">November</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sun">1</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">2</td>
                     <td class="tue">3</td>
                     <td class="wed">4</td>
                     <td class="thu">5</td>
                     <td class="fri">6</td>
                     <td class="sat">7</td>
                     <td class="sun">8</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">9</td>
                     <td class="tue">10</td>
                     <td class="wed">11</td>
                     <td class="thu">12</td>
                     <td class="fri">13</td>
                     <td class="sat">14</td>
                     <td class="sun">15</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">16</td>
                     <td class="tue">17</td>
                     <td class="wed">18</td>
                     <td class="thu">19</td>
                     <td class="fri">20</td>
                     <td class="sat">21</td>
                     <td class="sun">22</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">23</td>
                     <td class="tue">24</td>
                     <td class="wed">25</td>
                     <td class="thu">26</td>
                     <td class="fri">27</td>
                     <td class="sat">28</td>
                     <td class="sun">29</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">December</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="tue">1</td>
                     <td class="wed">2</td>
                     <td class="thu">3</td>
                     <td class="fri">4</td>
                     <td class="sat">5</td>
                     <td class="sun">6</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">7</td>
                     <td class="tue">8</td>
                     <td class="wed">9</td>
                     <td class="thu">10</td>
                     <td class="fri">11</td>
                     <td class="sat">12</td>
                     <td class="sun">13</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">14</td>
                     <td class="tue">15</td>
                     <td class="wed">16</td>
                     <td class="thu">17</td>
                     <td class="fri">18</td>
                     <td class="sat">19</td>
                     <td class="sun">20</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">21</td>
                     <td class="tue">22</td>
                     <td class="wed">23</td>
                     <td class="thu">24</td>
                     <td class="fri">25</td>
                     <td class="sat">26</td>
                     <td class="sun">27</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">28</td>
                     <td class="tue">29</td>
                     <td class="wed">30</td>
                     <td class="thu">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
      </table>
   </body>
   \n
</html>
\n'

Example2:

Approach:

  • Import calendar module using the import keyword.
  • Give the year as static input and store it in a variable.
  • Give the width as static input and store it in another variable.
  • Call the HTMLCalendar() function by setting firstweekday=0 and store it in another variable.
  • Apply formatyearpage() method to the above text calendar by passing the given year, width and encoding= None as the arguments and store it in another variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the year as static input and store it in a variable.
gvn_yr = 2017
# Give the width as static input and store it in another variable.
gvn_widt = 4
# Call the HTMLCalendar() function by setting firstweekday=0 and store it in
# another variable.
txt_calndr = calendar.HTMLCalendar(firstweekday=0)
# Apply formatyearpage() method to the above text calendar by passing the given year,
# width and encoding= None as the arguments and store it in another variable.
rslt = txt_calndr.formatyearpage(gvn_yr, gvn_widt, encoding=None)
# Print the above result.
print(rslt)

Output:

b'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n
<html>
   \n
   <head>
      \n
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      \n
      <link rel="stylesheet" type="text/css" href="calendar.css" />
      \n
      <title>Calendar for 2017</title>
      \n
   </head>
   \n
   <body>
      \n
      <table border="0" cellpadding="0" cellspacing="0" class="year">
         \n
         <tr>
            <th colspan="4" class="year">2017</th>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">January</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sun">1</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">2</td>
                     <td class="tue">3</td>
                     <td class="wed">4</td>
                     <td class="thu">5</td>
                     <td class="fri">6</td>
                     <td class="sat">7</td>
                     <td class="sun">8</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">9</td>
                     <td class="tue">10</td>
                     <td class="wed">11</td>
                     <td class="thu">12</td>
                     <td class="fri">13</td>
                     <td class="sat">14</td>
                     <td class="sun">15</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">16</td>
                     <td class="tue">17</td>
                     <td class="wed">18</td>
                     <td class="thu">19</td>
                     <td class="fri">20</td>
                     <td class="sat">21</td>
                     <td class="sun">22</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">23</td>
                     <td class="tue">24</td>
                     <td class="wed">25</td>
                     <td class="thu">26</td>
                     <td class="fri">27</td>
                     <td class="sat">28</td>
                     <td class="sun">29</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">30</td>
                     <td class="tue">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">February</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="wed">1</td>
                     <td class="thu">2</td>
                     <td class="fri">3</td>
                     <td class="sat">4</td>
                     <td class="sun">5</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">6</td>
                     <td class="tue">7</td>
                     <td class="wed">8</td>
                     <td class="thu">9</td>
                     <td class="fri">10</td>
                     <td class="sat">11</td>
                     <td class="sun">12</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">13</td>
                     <td class="tue">14</td>
                     <td class="wed">15</td>
                     <td class="thu">16</td>
                     <td class="fri">17</td>
                     <td class="sat">18</td>
                     <td class="sun">19</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">20</td>
                     <td class="tue">21</td>
                     <td class="wed">22</td>
                     <td class="thu">23</td>
                     <td class="fri">24</td>
                     <td class="sat">25</td>
                     <td class="sun">26</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">27</td>
                     <td class="tue">28</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">March</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="wed">1</td>
                     <td class="thu">2</td>
                     <td class="fri">3</td>
                     <td class="sat">4</td>
                     <td class="sun">5</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">6</td>
                     <td class="tue">7</td>
                     <td class="wed">8</td>
                     <td class="thu">9</td>
                     <td class="fri">10</td>
                     <td class="sat">11</td>
                     <td class="sun">12</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">13</td>
                     <td class="tue">14</td>
                     <td class="wed">15</td>
                     <td class="thu">16</td>
                     <td class="fri">17</td>
                     <td class="sat">18</td>
                     <td class="sun">19</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">20</td>
                     <td class="tue">21</td>
                     <td class="wed">22</td>
                     <td class="thu">23</td>
                     <td class="fri">24</td>
                     <td class="sat">25</td>
                     <td class="sun">26</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">27</td>
                     <td class="tue">28</td>
                     <td class="wed">29</td>
                     <td class="thu">30</td>
                     <td class="fri">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">April</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sat">1</td>
                     <td class="sun">2</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">3</td>
                     <td class="tue">4</td>
                     <td class="wed">5</td>
                     <td class="thu">6</td>
                     <td class="fri">7</td>
                     <td class="sat">8</td>
                     <td class="sun">9</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">10</td>
                     <td class="tue">11</td>
                     <td class="wed">12</td>
                     <td class="thu">13</td>
                     <td class="fri">14</td>
                     <td class="sat">15</td>
                     <td class="sun">16</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">17</td>
                     <td class="tue">18</td>
                     <td class="wed">19</td>
                     <td class="thu">20</td>
                     <td class="fri">21</td>
                     <td class="sat">22</td>
                     <td class="sun">23</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">24</td>
                     <td class="tue">25</td>
                     <td class="wed">26</td>
                     <td class="thu">27</td>
                     <td class="fri">28</td>
                     <td class="sat">29</td>
                     <td class="sun">30</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">May</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">1</td>
                     <td class="tue">2</td>
                     <td class="wed">3</td>
                     <td class="thu">4</td>
                     <td class="fri">5</td>
                     <td class="sat">6</td>
                     <td class="sun">7</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">8</td>
                     <td class="tue">9</td>
                     <td class="wed">10</td>
                     <td class="thu">11</td>
                     <td class="fri">12</td>
                     <td class="sat">13</td>
                     <td class="sun">14</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">15</td>
                     <td class="tue">16</td>
                     <td class="wed">17</td>
                     <td class="thu">18</td>
                     <td class="fri">19</td>
                     <td class="sat">20</td>
                     <td class="sun">21</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">22</td>
                     <td class="tue">23</td>
                     <td class="wed">24</td>
                     <td class="thu">25</td>
                     <td class="fri">26</td>
                     <td class="sat">27</td>
                     <td class="sun">28</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">29</td>
                     <td class="tue">30</td>
                     <td class="wed">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">June</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="thu">1</td>
                     <td class="fri">2</td>
                     <td class="sat">3</td>
                     <td class="sun">4</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">5</td>
                     <td class="tue">6</td>
                     <td class="wed">7</td>
                     <td class="thu">8</td>
                     <td class="fri">9</td>
                     <td class="sat">10</td>
                     <td class="sun">11</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">12</td>
                     <td class="tue">13</td>
                     <td class="wed">14</td>
                     <td class="thu">15</td>
                     <td class="fri">16</td>
                     <td class="sat">17</td>
                     <td class="sun">18</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">19</td>
                     <td class="tue">20</td>
                     <td class="wed">21</td>
                     <td class="thu">22</td>
                     <td class="fri">23</td>
                     <td class="sat">24</td>
                     <td class="sun">25</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">26</td>
                     <td class="tue">27</td>
                     <td class="wed">28</td>
                     <td class="thu">29</td>
                     <td class="fri">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">July</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sat">1</td>
                     <td class="sun">2</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">3</td>
                     <td class="tue">4</td>
                     <td class="wed">5</td>
                     <td class="thu">6</td>
                     <td class="fri">7</td>
                     <td class="sat">8</td>
                     <td class="sun">9</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">10</td>
                     <td class="tue">11</td>
                     <td class="wed">12</td>
                     <td class="thu">13</td>
                     <td class="fri">14</td>
                     <td class="sat">15</td>
                     <td class="sun">16</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">17</td>
                     <td class="tue">18</td>
                     <td class="wed">19</td>
                     <td class="thu">20</td>
                     <td class="fri">21</td>
                     <td class="sat">22</td>
                     <td class="sun">23</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">24</td>
                     <td class="tue">25</td>
                     <td class="wed">26</td>
                     <td class="thu">27</td>
                     <td class="fri">28</td>
                     <td class="sat">29</td>
                     <td class="sun">30</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">August</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="tue">1</td>
                     <td class="wed">2</td>
                     <td class="thu">3</td>
                     <td class="fri">4</td>
                     <td class="sat">5</td>
                     <td class="sun">6</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">7</td>
                     <td class="tue">8</td>
                     <td class="wed">9</td>
                     <td class="thu">10</td>
                     <td class="fri">11</td>
                     <td class="sat">12</td>
                     <td class="sun">13</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">14</td>
                     <td class="tue">15</td>
                     <td class="wed">16</td>
                     <td class="thu">17</td>
                     <td class="fri">18</td>
                     <td class="sat">19</td>
                     <td class="sun">20</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">21</td>
                     <td class="tue">22</td>
                     <td class="wed">23</td>
                     <td class="thu">24</td>
                     <td class="fri">25</td>
                     <td class="sat">26</td>
                     <td class="sun">27</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">28</td>
                     <td class="tue">29</td>
                     <td class="wed">30</td>
                     <td class="thu">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">September</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="fri">1</td>
                     <td class="sat">2</td>
                     <td class="sun">3</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">4</td>
                     <td class="tue">5</td>
                     <td class="wed">6</td>
                     <td class="thu">7</td>
                     <td class="fri">8</td>
                     <td class="sat">9</td>
                     <td class="sun">10</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">11</td>
                     <td class="tue">12</td>
                     <td class="wed">13</td>
                     <td class="thu">14</td>
                     <td class="fri">15</td>
                     <td class="sat">16</td>
                     <td class="sun">17</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">18</td>
                     <td class="tue">19</td>
                     <td class="wed">20</td>
                     <td class="thu">21</td>
                     <td class="fri">22</td>
                     <td class="sat">23</td>
                     <td class="sun">24</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">25</td>
                     <td class="tue">26</td>
                     <td class="wed">27</td>
                     <td class="thu">28</td>
                     <td class="fri">29</td>
                     <td class="sat">30</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">October</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sun">1</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">2</td>
                     <td class="tue">3</td>
                     <td class="wed">4</td>
                     <td class="thu">5</td>
                     <td class="fri">6</td>
                     <td class="sat">7</td>
                     <td class="sun">8</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">9</td>
                     <td class="tue">10</td>
                     <td class="wed">11</td>
                     <td class="thu">12</td>
                     <td class="fri">13</td>
                     <td class="sat">14</td>
                     <td class="sun">15</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">16</td>
                     <td class="tue">17</td>
                     <td class="wed">18</td>
                     <td class="thu">19</td>
                     <td class="fri">20</td>
                     <td class="sat">21</td>
                     <td class="sun">22</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">23</td>
                     <td class="tue">24</td>
                     <td class="wed">25</td>
                     <td class="thu">26</td>
                     <td class="fri">27</td>
                     <td class="sat">28</td>
                     <td class="sun">29</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">30</td>
                     <td class="tue">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">November</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="wed">1</td>
                     <td class="thu">2</td>
                     <td class="fri">3</td>
                     <td class="sat">4</td>
                     <td class="sun">5</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">6</td>
                     <td class="tue">7</td>
                     <td class="wed">8</td>
                     <td class="thu">9</td>
                     <td class="fri">10</td>
                     <td class="sat">11</td>
                     <td class="sun">12</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">13</td>
                     <td class="tue">14</td>
                     <td class="wed">15</td>
                     <td class="thu">16</td>
                     <td class="fri">17</td>
                     <td class="sat">18</td>
                     <td class="sun">19</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">20</td>
                     <td class="tue">21</td>
                     <td class="wed">22</td>
                     <td class="thu">23</td>
                     <td class="fri">24</td>
                     <td class="sat">25</td>
                     <td class="sun">26</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">27</td>
                     <td class="tue">28</td>
                     <td class="wed">29</td>
                     <td class="thu">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">December</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="fri">1</td>
                     <td class="sat">2</td>
                     <td class="sun">3</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">4</td>
                     <td class="tue">5</td>
                     <td class="wed">6</td>
                     <td class="thu">7</td>
                     <td class="fri">8</td>
                     <td class="sat">9</td>
                     <td class="sun">10</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">11</td>
                     <td class="tue">12</td>
                     <td class="wed">13</td>
                     <td class="thu">14</td>
                     <td class="fri">15</td>
                     <td class="sat">16</td>
                     <td class="sun">17</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">18</td>
                     <td class="tue">19</td>
                     <td class="wed">20</td>
                     <td class="thu">21</td>
                     <td class="fri">22</td>
                     <td class="sat">23</td>
                     <td class="sun">24</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">25</td>
                     <td class="tue">26</td>
                     <td class="wed">27</td>
                     <td class="thu">28</td>
                     <td class="fri">29</td>
                     <td class="sat">30</td>
                     <td class="sun">31</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
      </table>
   </body>
   \n
</html>
\n'

Method #2: Using Built-in Functions (User Input)

Example1:

Approach:

  • Import calendar module using the import keyword.
  • Give the year as user input using the int(input()) function and store it in a variable.
  • Call the HTMLCalendar() function by setting firstweekday=0 and store it in another variable.
  • Apply formatyearpage() method to the above text calendar by passing the given year as an argument and store it in another variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import calendar module using the import keyword.
import calendar
# Give the year as user input using the int(input()) function and store it in a variable.
gvn_yr =  int(input("Enter some random year = "))
# Call the HTMLCalendar() function by setting firstweekday=0 and store it in
# another variable.
txt_calndr = calendar.HTMLCalendar(firstweekday=0)
# Apply formatyearpage() method to the above text calendar by passing the given year,
# as an argument and store it in another variable.
rslt = txt_calndr.formatyearpage(gvn_yr)
# Print the above result.
print(rslt)

Output:

Enter some random year = 2020
b'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n
<html>
   \n
   <head>
      \n
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      \n
      <link rel="stylesheet" type="text/css" href="calendar.css" />
      \n
      <title>Calendar for 2020</title>
      \n
   </head>
   \n
   <body>
      \n
      <table border="0" cellpadding="0" cellspacing="0" class="year">
         \n
         <tr>
            <th colspan="3" class="year">2020</th>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">January</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="wed">1</td>
                     <td class="thu">2</td>
                     <td class="fri">3</td>
                     <td class="sat">4</td>
                     <td class="sun">5</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">6</td>
                     <td class="tue">7</td>
                     <td class="wed">8</td>
                     <td class="thu">9</td>
                     <td class="fri">10</td>
                     <td class="sat">11</td>
                     <td class="sun">12</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">13</td>
                     <td class="tue">14</td>
                     <td class="wed">15</td>
                     <td class="thu">16</td>
                     <td class="fri">17</td>
                     <td class="sat">18</td>
                     <td class="sun">19</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">20</td>
                     <td class="tue">21</td>
                     <td class="wed">22</td>
                     <td class="thu">23</td>
                     <td class="fri">24</td>
                     <td class="sat">25</td>
                     <td class="sun">26</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">27</td>
                     <td class="tue">28</td>
                     <td class="wed">29</td>
                     <td class="thu">30</td>
                     <td class="fri">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">February</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sat">1</td>
                     <td class="sun">2</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">3</td>
                     <td class="tue">4</td>
                     <td class="wed">5</td>
                     <td class="thu">6</td>
                     <td class="fri">7</td>
                     <td class="sat">8</td>
                     <td class="sun">9</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">10</td>
                     <td class="tue">11</td>
                     <td class="wed">12</td>
                     <td class="thu">13</td>
                     <td class="fri">14</td>
                     <td class="sat">15</td>
                     <td class="sun">16</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">17</td>
                     <td class="tue">18</td>
                     <td class="wed">19</td>
                     <td class="thu">20</td>
                     <td class="fri">21</td>
                     <td class="sat">22</td>
                     <td class="sun">23</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">24</td>
                     <td class="tue">25</td>
                     <td class="wed">26</td>
                     <td class="thu">27</td>
                     <td class="fri">28</td>
                     <td class="sat">29</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">March</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sun">1</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">2</td>
                     <td class="tue">3</td>
                     <td class="wed">4</td>
                     <td class="thu">5</td>
                     <td class="fri">6</td>
                     <td class="sat">7</td>
                     <td class="sun">8</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">9</td>
                     <td class="tue">10</td>
                     <td class="wed">11</td>
                     <td class="thu">12</td>
                     <td class="fri">13</td>
                     <td class="sat">14</td>
                     <td class="sun">15</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">16</td>
                     <td class="tue">17</td>
                     <td class="wed">18</td>
                     <td class="thu">19</td>
                     <td class="fri">20</td>
                     <td class="sat">21</td>
                     <td class="sun">22</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">23</td>
                     <td class="tue">24</td>
                     <td class="wed">25</td>
                     <td class="thu">26</td>
                     <td class="fri">27</td>
                     <td class="sat">28</td>
                     <td class="sun">29</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">30</td>
                     <td class="tue">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">April</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="wed">1</td>
                     <td class="thu">2</td>
                     <td class="fri">3</td>
                     <td class="sat">4</td>
                     <td class="sun">5</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">6</td>
                     <td class="tue">7</td>
                     <td class="wed">8</td>
                     <td class="thu">9</td>
                     <td class="fri">10</td>
                     <td class="sat">11</td>
                     <td class="sun">12</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">13</td>
                     <td class="tue">14</td>
                     <td class="wed">15</td>
                     <td class="thu">16</td>
                     <td class="fri">17</td>
                     <td class="sat">18</td>
                     <td class="sun">19</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">20</td>
                     <td class="tue">21</td>
                     <td class="wed">22</td>
                     <td class="thu">23</td>
                     <td class="fri">24</td>
                     <td class="sat">25</td>
                     <td class="sun">26</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">27</td>
                     <td class="tue">28</td>
                     <td class="wed">29</td>
                     <td class="thu">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">May</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="fri">1</td>
                     <td class="sat">2</td>
                     <td class="sun">3</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">4</td>
                     <td class="tue">5</td>
                     <td class="wed">6</td>
                     <td class="thu">7</td>
                     <td class="fri">8</td>
                     <td class="sat">9</td>
                     <td class="sun">10</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">11</td>
                     <td class="tue">12</td>
                     <td class="wed">13</td>
                     <td class="thu">14</td>
                     <td class="fri">15</td>
                     <td class="sat">16</td>
                     <td class="sun">17</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">18</td>
                     <td class="tue">19</td>
                     <td class="wed">20</td>
                     <td class="thu">21</td>
                     <td class="fri">22</td>
                     <td class="sat">23</td>
                     <td class="sun">24</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">25</td>
                     <td class="tue">26</td>
                     <td class="wed">27</td>
                     <td class="thu">28</td>
                     <td class="fri">29</td>
                     <td class="sat">30</td>
                     <td class="sun">31</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">June</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">1</td>
                     <td class="tue">2</td>
                     <td class="wed">3</td>
                     <td class="thu">4</td>
                     <td class="fri">5</td>
                     <td class="sat">6</td>
                     <td class="sun">7</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">8</td>
                     <td class="tue">9</td>
                     <td class="wed">10</td>
                     <td class="thu">11</td>
                     <td class="fri">12</td>
                     <td class="sat">13</td>
                     <td class="sun">14</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">15</td>
                     <td class="tue">16</td>
                     <td class="wed">17</td>
                     <td class="thu">18</td>
                     <td class="fri">19</td>
                     <td class="sat">20</td>
                     <td class="sun">21</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">22</td>
                     <td class="tue">23</td>
                     <td class="wed">24</td>
                     <td class="thu">25</td>
                     <td class="fri">26</td>
                     <td class="sat">27</td>
                     <td class="sun">28</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">29</td>
                     <td class="tue">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">July</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="wed">1</td>
                     <td class="thu">2</td>
                     <td class="fri">3</td>
                     <td class="sat">4</td>
                     <td class="sun">5</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">6</td>
                     <td class="tue">7</td>
                     <td class="wed">8</td>
                     <td class="thu">9</td>
                     <td class="fri">10</td>
                     <td class="sat">11</td>
                     <td class="sun">12</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">13</td>
                     <td class="tue">14</td>
                     <td class="wed">15</td>
                     <td class="thu">16</td>
                     <td class="fri">17</td>
                     <td class="sat">18</td>
                     <td class="sun">19</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">20</td>
                     <td class="tue">21</td>
                     <td class="wed">22</td>
                     <td class="thu">23</td>
                     <td class="fri">24</td>
                     <td class="sat">25</td>
                     <td class="sun">26</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">27</td>
                     <td class="tue">28</td>
                     <td class="wed">29</td>
                     <td class="thu">30</td>
                     <td class="fri">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">August</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sat">1</td>
                     <td class="sun">2</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">3</td>
                     <td class="tue">4</td>
                     <td class="wed">5</td>
                     <td class="thu">6</td>
                     <td class="fri">7</td>
                     <td class="sat">8</td>
                     <td class="sun">9</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">10</td>
                     <td class="tue">11</td>
                     <td class="wed">12</td>
                     <td class="thu">13</td>
                     <td class="fri">14</td>
                     <td class="sat">15</td>
                     <td class="sun">16</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">17</td>
                     <td class="tue">18</td>
                     <td class="wed">19</td>
                     <td class="thu">20</td>
                     <td class="fri">21</td>
                     <td class="sat">22</td>
                     <td class="sun">23</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">24</td>
                     <td class="tue">25</td>
                     <td class="wed">26</td>
                     <td class="thu">27</td>
                     <td class="fri">28</td>
                     <td class="sat">29</td>
                     <td class="sun">30</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">September</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="tue">1</td>
                     <td class="wed">2</td>
                     <td class="thu">3</td>
                     <td class="fri">4</td>
                     <td class="sat">5</td>
                     <td class="sun">6</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">7</td>
                     <td class="tue">8</td>
                     <td class="wed">9</td>
                     <td class="thu">10</td>
                     <td class="fri">11</td>
                     <td class="sat">12</td>
                     <td class="sun">13</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">14</td>
                     <td class="tue">15</td>
                     <td class="wed">16</td>
                     <td class="thu">17</td>
                     <td class="fri">18</td>
                     <td class="sat">19</td>
                     <td class="sun">20</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">21</td>
                     <td class="tue">22</td>
                     <td class="wed">23</td>
                     <td class="thu">24</td>
                     <td class="fri">25</td>
                     <td class="sat">26</td>
                     <td class="sun">27</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">28</td>
                     <td class="tue">29</td>
                     <td class="wed">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
         <tr>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">October</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="thu">1</td>
                     <td class="fri">2</td>
                     <td class="sat">3</td>
                     <td class="sun">4</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">5</td>
                     <td class="tue">6</td>
                     <td class="wed">7</td>
                     <td class="thu">8</td>
                     <td class="fri">9</td>
                     <td class="sat">10</td>
                     <td class="sun">11</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">12</td>
                     <td class="tue">13</td>
                     <td class="wed">14</td>
                     <td class="thu">15</td>
                     <td class="fri">16</td>
                     <td class="sat">17</td>
                     <td class="sun">18</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">19</td>
                     <td class="tue">20</td>
                     <td class="wed">21</td>
                     <td class="thu">22</td>
                     <td class="fri">23</td>
                     <td class="sat">24</td>
                     <td class="sun">25</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">26</td>
                     <td class="tue">27</td>
                     <td class="wed">28</td>
                     <td class="thu">29</td>
                     <td class="fri">30</td>
                     <td class="sat">31</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">November</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="sun">1</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">2</td>
                     <td class="tue">3</td>
                     <td class="wed">4</td>
                     <td class="thu">5</td>
                     <td class="fri">6</td>
                     <td class="sat">7</td>
                     <td class="sun">8</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">9</td>
                     <td class="tue">10</td>
                     <td class="wed">11</td>
                     <td class="thu">12</td>
                     <td class="fri">13</td>
                     <td class="sat">14</td>
                     <td class="sun">15</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">16</td>
                     <td class="tue">17</td>
                     <td class="wed">18</td>
                     <td class="thu">19</td>
                     <td class="fri">20</td>
                     <td class="sat">21</td>
                     <td class="sun">22</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">23</td>
                     <td class="tue">24</td>
                     <td class="wed">25</td>
                     <td class="thu">26</td>
                     <td class="fri">27</td>
                     <td class="sat">28</td>
                     <td class="sun">29</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">30</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
            <td>
               <table border="0" cellpadding="0" cellspacing="0" class="month">
                  \n
                  <tr>
                     <th colspan="7" class="month">December</th>
                  </tr>
                  \n
                  <tr>
                     <th class="mon">Mon</th>
                     <th class="tue">Tue</th>
                     <th class="wed">Wed</th>
                     <th class="thu">Thu</th>
                     <th class="fri">Fri</th>
                     <th class="sat">Sat</th>
                     <th class="sun">Sun</th>
                  </tr>
                  \n
                  <tr>
                     <td class="noday">&nbsp;</td>
                     <td class="tue">1</td>
                     <td class="wed">2</td>
                     <td class="thu">3</td>
                     <td class="fri">4</td>
                     <td class="sat">5</td>
                     <td class="sun">6</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">7</td>
                     <td class="tue">8</td>
                     <td class="wed">9</td>
                     <td class="thu">10</td>
                     <td class="fri">11</td>
                     <td class="sat">12</td>
                     <td class="sun">13</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">14</td>
                     <td class="tue">15</td>
                     <td class="wed">16</td>
                     <td class="thu">17</td>
                     <td class="fri">18</td>
                     <td class="sat">19</td>
                     <td class="sun">20</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">21</td>
                     <td class="tue">22</td>
                     <td class="wed">23</td>
                     <td class="thu">24</td>
                     <td class="fri">25</td>
                     <td class="sat">26</td>
                     <td class="sun">27</td>
                  </tr>
                  \n
                  <tr>
                     <td class="mon">28</td>
                     <td class="tue">29</td>
                     <td class="wed">30</td>
                     <td class="thu">31</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                     <td class="noday">&nbsp;</td>
                  </tr>
                  \n
               </table>
               \n
            </td>
         </tr>
      </table>
   </body>
   \n
</html>
\n'

 

Python Program for HTMLCalendar formatyearpage() Method with Examples Read More »