What Is the Python Standard Library?
Discover the key modules of the Python Standard Library including datetime, math, heapq, and random. Learn how to use these built-in tools to manage dates, perform mathematical operations, handle data structures, and generate random numbers, enhancing your Python programming skills.
We'll cover the following...
The Python Standard Library (PSL), is a collection of pre-defined modules that contain many useful utilities which spare us a lot of time. These include different types of complex mathematical functions, high-level data types, network programming tools, and this is just the tip of the iceberg!
Let’s dive in.
datetime
Let’s start by importing the datetime module which contains several methods related to the current date and time. As always, these methods can be accessed using the . operator:
Explanation
Here is the explanation of the code provided above:
-
Line 2: Imports
datetimemodule. -
Lines 3–4:
todayis a method of thedatetime.dateclass that returns the current date as adatetime.date...