InfoparkDailyCAREER TOOLS

Python · Lesson 9 of 9

Modules & the standard library

import, from … import, and useful built-in modules: math, random, datetime, json.

A module is a file of Python code you can reuse with import. Python ships with a large standard library, so many tasks need no installation.

  • math — sqrt, ceil, floor, pi
  • random — choice, randint, shuffle
  • datetime — dates, times and differences between them
  • json — convert between Python dicts and JSON text (used by every web API)

Third-party packages (requests, pandas, Django) are installed with pip install name, usually inside a virtual environment created with python -m venv .venv.

Try it yourself

Press Run to see the output.

Edit and press Run (or Ctrl/⌘ + Enter). Python runs in your browser — the first run downloads the Python engine and takes a few seconds.

Key points

  • import module or from module import name.
  • The standard library covers maths, dates, JSON and more.
  • Use pip + virtual environments for third-party packages.

Quick check

Which module converts a dict to JSON text?

Practice task

Use datetime.date to calculate how many days are left until 1 January 2027, and print it in an f-string.

Interview corner

What is a virtual environment and why use one?

An isolated folder with its own Python packages. It keeps each project's dependencies separate, so versions don't clash between projects.

What does if __name__ == "__main__": do?

Code under it runs only when the file is executed directly, not when it is imported as a module — useful for scripts that also provide reusable functions.

Further reading

Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.

Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.