Python comes with a rich standard library that includes a wide variety of modules covering different aspects of programming, such as file handling, networking, data structures, mathematics, and more. Here are some of the commonly used standard modules in Python:
os and os.path:
os: Provides a way of using operating system-dependent functionality.
os.path: Module for common path manipulations.
sys: Provides access to some variables used or maintained by the Python interpreter and functions that interact strongly with the interpreter.
math: Mathematical functions and constants.
random: Implements pseudo-random number generators for generating random numbers.
datetime: Supplies classes for working with dates and times.
urllib: Provides a high-level interface for fetching data across the World Wide Web.
collections: Implements several specialized container datatypes like namedtuple, Counter, and deque.
re (Regular Expressions): Provides regular expression matching operations.
csv: Implements classes to read and write tabular data in CSV format.
sqlite3: Provides a lightweight disk-based database.
itertools: Implements a set of fast, memory-efficient tools.
functools: Provides higher-order functions and operations on callable objects.
logging: Flexible event logging system for applications.
argparse: Parser for command-line options, arguments, and subcommands.
sysconfig: Accesses Python’s configuration information.
time: Provides various time-related functions.
subprocess: Spawns processes, connects to their input/output/error pipes, and obtains their return codes.
socket: Provides low-level network programming.
collections: Implements specialized container datatypes, such as named tuples, deques, and Counter.
These are just a few examples, and there are many more modules in the Python standard library. When working on a project, it’s a good idea to explore the standard library to find modules that can simplify and enhance your development process. Always refer to the official Python documentation for detailed information on each module.
How to Import Modules in Python?
In Python, we may import functions from one module into our program, or as we say into, another module.
For this, we make use of the import Python keyword. In the Python window, we add the next to import keyword, the name of the module we need to import. We will import the module we defined earlier example_module.
The functions that we defined in the example_module are not immediately imported into the present program. Only the name of the module, i.e., example_ module, is imported here.