Posts

Showing posts with the label Python import statement

Python Modules

Python Modules: In this article, you will learn to create and import custom modules in Python. Also, you will find different techniques to import and use custom and built-in modules in Python. Python Modules Modules refer to a file containing Python statements and definitions. A file containing Python code, for e.g.: example.py, is called a module and its module name would be example. We use modules to break down large programs into small manageable and organized files. Furthermore, modules provide reusability of code. We can define our most used functions in a module and import it, instead of copying their definitions into different programs. Let us create a module. Type the following and save it as example.py. # Python Module example def   add(a, b):    """This program adds two    numbers and return the result"""    result = a + b    return result Here, we have defined a function add() inside a module na...