What is a __module__? why?

A module is a Python file with one or more functions and variables. These functions and variables can be called from your program by importing a module.

Modules can be used to organize your code.

**You may like**

**30 Days of Python Unlock your Python Potential****Complete Python Bootcamp: Go from zero to hero in Python**

In this example we use the math module. This module has many functions such as sine, cosine as well as variables:

0 1 2 3 4 5 6 |
import math print(math.pi) x = math.sin(1) print(x) |

### Find available functions and variables in a Python module

To find the available functions in a module, you can use this code:

0 1 2 3 4 5 |
import math content = dir(math) print(content) |

A list will be returned with all functions and variables:

$ python example.py

[‘__doc__’, ‘__name__’, ‘__package__’, ‘acos’, ‘acosh’, ‘asin’, ‘asinh’, ‘atan’, ‘atan2’, ‘atanh’,

‘ceil’, ‘copysign’, ‘cos’, ‘cosh’, ‘degrees’, ‘e’, ‘erf’, ‘erfc’, ‘exp’, ‘expm1’, ‘fabs’, ‘factorial’,

‘floor’, ‘fmod’, ‘frexp’, ‘fsum’, ‘gamma’, ‘hypot’, ‘isinf’, ‘isnan’, ‘ldexp’, ‘lgamma’, ‘log’, ‘log10’,

‘log1p’, ‘modf’, ‘pi’, ‘pow’, ‘radians’, ‘sin’, ‘sinh’, ‘sqrt’, ‘tan’, ‘tanh’, ‘trunc’]

[‘__doc__’, ‘__name__’, ‘__package__’, ‘acos’, ‘acosh’, ‘asin’, ‘asinh’, ‘atan’, ‘atan2’, ‘atanh’,

‘ceil’, ‘copysign’, ‘cos’, ‘cosh’, ‘degrees’, ‘e’, ‘erf’, ‘erfc’, ‘exp’, ‘expm1’, ‘fabs’, ‘factorial’,

‘floor’, ‘fmod’, ‘frexp’, ‘fsum’, ‘gamma’, ‘hypot’, ‘isinf’, ‘isnan’, ‘ldexp’, ‘lgamma’, ‘log’, ‘log10’,

‘log1p’, ‘modf’, ‘pi’, ‘pow’, ‘radians’, ‘sin’, ‘sinh’, ‘sqrt’, ‘tan’, ‘tanh’, ‘trunc’]

### Create your own module

First create a Python file with a function. We call this file hello.py and we have one function:

0 1 2 3 |
def hello(): print("Hello World") |

Now that we have create a module named *hello* we can use it in our program test.py

0 1 2 3 4 5 6 |
# Import your module import hello # Call of function defined in module hello.hello() |