How to use modules in Python

Modules are packages of code that can be imported into a Python program. To use a module, you must first import it using the import statement. For example, to import the math module, you would write:

import math

Once imported, you can use the functions and classes defined in the module. For example, to use the sqrt() function from the math module, you would write:

result = math.sqrt(25)

You can also import specific functions or classes from a module. For example, to import the sqrt() function only, you would write:

from math import sqrt

Now you can use the sqrt() function without having to specify the module name:

result = sqrt(25)