Python Modules

A Python module is a file containing Python definitions and statements.Modules typically use lowercase letters with optional underscores.

  • Main Module: When directly executed, a Python file is considered the main module (__main__).
    • It forms the basis of a complete Python program and can import other modules but is not intended for import by other modules.
  • Imported Modules: These are modules included in the main module or other imported modules. Their statements execute only once, during the first import, usually for initialization purposes.
  • Standard (Built-in) Modules: Python's Standard Library includes predefined standard modules like math and random.

Benefits:

  • Modular software design enhances organization, reusability, and maintainability.
  • Each module encapsulates a set of related functionalities.