Python's standard library is extensive. The `collections` module adds specialized containers: `namedtuple` creates tuple subclasses with named fields, `OrderedDict` maintains insertion order (regular dicts also do in Python 3.7+), `defaultdict` provides defaults for missing keys, `Counter` tallies hashable objects, `deque` offers fast appends and pops at both ends, and `ChainMap` groups multiple dicts as one mapping. `itertools` provides iterator building blocks like `chain`, `cycle`, and `combinations`, while `functools` complements `operator` (functional versions of operators such as `operator.add`) with `lru_cache`, `partial`, and `reduce`. `heapq` implements priority queues and `bisect` provides binary search on sorted lists. Data interchange is handled by `json` (interoperable text), `pickle` (Python-specific binary — convenient but insecure with untrusted data), `csv` for tabular files, and `sqlite3` for embedded SQL. Networking lives in `urllib` (stdlib HTTP), `socket` (low-level), and the third-party `requests`. Numerical work spans `math` (functions and constants), `decimal` (arbitrary precision), `fractions` (rationals), `random` (pseudo-random), `secrets` (cryptographically secure), `hashlib` (cryptographic hashes), and `base64` (encoding). The `timeit` module benchmarks small snippets, complementing IPython's `%timeit` magic. Filesystem paths are modernized through `pathlib`, an object-oriented alternative to `os.path`.
For diagnostics and tooling, Python offers interactive environments and profilers. The REPL is the built-in interactive prompt; IPython enhances it with magics like `%timeit`, while Jupyter Notebook combines code, output, and narrative in a web app. Profiling measures performance to find bottlenecks: `cProfile` is the built-in profiler, `line_profiler` profiles line-by-line, and `memory_profiler` tracks memory line-by-line. PEP 657 tracebacks pinpoint specific expressions. The `logging` module provides levels (DEBUG, INFO, WARNING, ERROR, CRITICAL), handlers that direct records to files, consoles, or networks, formatters that specify record layout, and `logging.config.dictConfig` for dictionary-based setup. `logging.exception()` logs an ERROR with a traceback, whereas `print()` simply writes to stdout.
Packaging has evolved significantly. `venv` creates lightweight virtual environments; `virtualenv` preceded it. `pip` installs packages from PyPI, with `pip freeze` listing installed versions. `requirements.txt` lists dependencies, while `pyproject.toml` (PEP 518/621) is the modern configuration standard. Packages are distributed as wheels (.whl) for fast installation or sdists (source distributions). Tools like Poetry and Pipenv combine dependency management with virtualenvs, while conda is popular in data science. A package's `__version__` attribute conventionally holds version info, following semantic versioning (Major.Minor.Patch).
Exception handling centers on `try`/`except`. `BaseException` is the root, while `Exception` is the parent of most user-facing errors. The `else` block runs only on success, `finally` always runs, `raise` triggers an exception, and `raise from` chains a new exception to its cause. Custom exceptions inherit from `Exception` or a subclass. Testing tools include `unittest` (xUnit-style), `pytest` (with fixtures, monkeypatching, mocks, and `parametrize`), `doctest` (tests embedded in docstrings), coverage measurement via coverage.py, `tox` for testing across Python versions, and `hypothesis` for property-based testing. Unit tests isolate single components, integration tests combine them, and end-to-end tests exercise the full system. Test-driven development writes tests before implementation.
Web frameworks vary in scope: Django is full-featured with ORM and admin, Flask is a lightweight microframework, FastAPI is async, type-hinted, and auto-documented, and `aiohttp` is async HTTP. Deployment standards are WSGI (synchronous) and ASGI (asynchronous), served by `gunicorn` and `uvicorn` respectively. Documentation is generated with Sphinx using reStructuredText, and docstrings provide in-code documentation accessible via `help()`. Memory management combines reference counting — trackable via `sys.getrefcount` — with a cyclic garbage collector that handles circular references. The `__del__` destructor runs when an object is about to be destroyed, and `weakref` creates references that do not prevent garbage collection. Numeric helpers round out the picture: `divmod` returns quotient and remainder, `abs` returns absolute value, and `round` uses banker's rounding by default.