1 min read

Load

The load function in Python is used to import a module, a file containing Python code, from the file system.

Syntax:

pythonload(module_name)

Parameters:

  • module_name: The name of the module to be loaded. This can be a package or a Python module file.

Example:

“`python

Import the math module

import math

Access functions from the math module

print(math.pi)print(math.sqrt(2))“`

Output:

3.141592653591.41421356237

Notes:

  • The load function is considered deprecated in Python 3 and replaced with the import statement.
  • The module name must be a valid Python identifier.
  • If the module is not found, an error will be raised.
  • The load function can also be used to load a module from a particular path. For example:

“`python

Import a module from a specific path

load(‘/home/user/my_module.py’)“`

Equivalent Import Statement:

“`pythonimport math

Same as load(math)

import math“`

Therefore, the load function is primarily used in older Python code and is not recommended for use in new code.

Disclaimer