Python Mastery โ€“ From Basics to Brilliance / Modules & Packages

Python Standard Library

๐Ÿ“š Python Standard Library

The Python Standard Library is a collection of pre-written modules and functions that come with Python.

You can use them without installing any external package.


๐Ÿ“ฆ Common Standard Library Modules

Module

Purpose

Example

math ๐Ÿงฎ

Mathematical operations

math.sqrt(25)

random ๐ŸŽฒ

Generate random values

random.randint(1, 10)

datetime ๐Ÿ“…

Date and time

datetime.now()

os ๐Ÿ’ป

Operating system operations

os.getcwd()

sys โš™๏ธ

Python/system information

sys.version

json ๐Ÿ”ค

Work with JSON data

json.loads()

re ๐Ÿ”Ž

Regular expressions

re.search()

collections ๐Ÿ“ฆ

Specialized data structures

Counter()

statistics ๐Ÿ“Š

Statistical calculations

statistics.mean()

functools ๐Ÿ› ๏ธ

Functional programming tools

reduce()


๐Ÿ”น Example

import math

print(math.sqrt(16)) #4.0

No installation is required because math is part of Python's Standard Library.
For example:

import math       # โœ… Standard Library

Whereas libraries such as numpy or pandas generally need to be installed separately.

๐Ÿง  Remember

Standard Library = A collection of ready-to-use tools that comes with Python.