{"id":27199,"date":"2022-04-18T00:47:39","date_gmt":"2022-04-17T19:17:39","guid":{"rendered":"https:\/\/python-programs.com\/?p=27199"},"modified":"2022-04-18T00:47:39","modified_gmt":"2022-04-17T19:17:39","slug":"python-holidays-library","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-holidays-library\/","title":{"rendered":"Python Holidays Library"},"content":{"rendered":"

Let us see about the holidays library here.<\/p>\n

holidays library in Python:<\/strong><\/p>\n

The holidays library will help to determine whether or not a particular day is a holiday in various countries. Only public holidays are visible to us.<\/p>\n

Syntax:<\/strong><\/p>\n

class holidays.HolidayBase(years=[], expand=True, observed=True, prov=None, state=None)<\/pre>\n

Parameters<\/strong><\/p>\n

years:<\/strong><\/p>\n

The years argument specifies an iterable list of integers that should be generated automatically by the holiday object. This is only used when the expand parameter is set to False. The years parameter’s default value is [].<\/p>\n

expand:<\/strong><\/p>\n

The expand is a boolean argument that specifies whether or not the holidays should be appended to the holidays object in new years. True is the default value.<\/p>\n

observed:<\/strong><\/p>\n

It is also a boolean argument. When set to True, it includes the observed day of a holiday that falls on a weekend, if applicable. True is the default value.<\/p>\n

prov:<\/strong><\/p>\n

It is a string that represents a province<\/p>\n

state:\u00a0<\/strong><\/p>\n

It is a string representing a state.<\/p>\n

Methods of holidays module<\/strong><\/h3>\n

get(key, default = None):<\/strong><\/p>\n

It returns the name of the holiday on the specified date in the key parameter. If more than one holiday falls on the same day, the names are separated by commas.<\/p>\n

getlist(key): <\/strong><\/p>\n

It returns a list of names for holidays.<\/p>\n

pop(key, default = None): <\/strong><\/p>\n

It removes the key from the holidays object.<\/p>\n

Before we work with this module, we should first install it.<\/p>\n

Installation:<\/strong><\/p>\n

\n
pip\u00a0install\u00a0holidays<\/pre>\n

Python Holidays Library<\/h2>\n

Printing the holidays in the specified Year<\/strong><\/h3>\n

Approach:<\/strong><\/p>\n