
A package is a directory structure which can contain modules and sub packages. Every package in Python is a directory which must contain a special file called __init.py__.
A python module can be defined as a python program file which contains a python code including python functions, class, or variables. In other words, we can say that our python code file saved with the extension (.py) is treated as the module.
When we break a program into modules, each modules should contain functions that perform related tasks. Commonly used modules that contains source code for generic needs are called Libraries.
- [PDF]
PYTHON MODULE
Structure of Python module A python module is simply a normal python file(.py) and contains functions, constants and other elements. Python module may contains following objects:
Introduction to Python and installation, data types: Int, float, Boolean, string, and list; variables, expressions, statements, precedence of operators, comments; modules, functions-- - function and its use, flow of execution, parameters and arguments.
User Defined Functions A function is a set of statements that performs a specific task; a common structuring elements that allows you to use a piece of code repeatedly in different part of program. Functions are also known as sub-routine, methods, procedure or subprogram. Syntax to create USER DEFINED FUNCTION def function_name([comma
In Python, a function is a group of related statements that performs a specific task. Functions help break our program into smaller and modular chunks. As our program. larger, manageable. A function is a block of organized, reusable code that is used to perform a single, related action.
Simply, a module is a file consisting of Python code. A module can define functions, classes and variables. A module can also include runnable code. The Python code for a module named aname normally resides in a file named aname.py. Here's an example of a simple module, support.py. print "Hello : ", par. return.
Why do you need modules ? A way to structure code into smaller logical units Encapsulation of functionality Reuse of code in different programs Your can write your own modules and packages or use any of the +100.000 existing packages from pypi.org
Package: A package is a collection of Python modules. Module is a single Python file containing function definitions; a package is a directory (folder) of Python modules containing an additional _ _init_ _.py file, to differentiate a package from a directory.
- Some results have been removed