An Overview of Modules in Python
Introduction
We live in an era where computer code governs the digital environment. Software is essential to the smooth operation of a variety of businesses, including healthcare, banking, military research, and many more. The process of developing software is made more accessible by a long number of programming languages.?
Python's built-in modules are adaptable and suitable for a variety of use scenarios, including developing websites and producing concurrently operating programs.
Meaning of Module
A module is a distinct group of parts that is simple to add, delete, or replace. A module generally can't function by itself. Modules are developed to complete a certain task.
Types of modules in Python?
Python allows for the logical and simple-to-understand coding organization. Python code files come in the form of modules. The specification of variables, classes, and functions is possible using these.??
Internal Modules
Since Python's cell-starting syntax supports ‘ex’, ‘input’, ‘int’, ‘float’, ‘complex’, ‘list’, ‘tuples’, and many more operations, these are automated actions.
Example 1
import platform
B = platform.system()
print(B)?
Output
Windows
Example 2
import math
dir(math)
Output?
acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp'
User-Created Modules
These are created by the user depending on their requirements, allowing us to create any module, function, or class and store them. Let's create a module. And save it as .py, type the following.
Example 1
def add (a,b):
A = 15
B = 14
print(add
????result = a+b
????return result
Example 2
Arithmetic .py?
def addition()
--------
--------
def subtraction()
--------
--------
领英推荐
def multiplication()
--------
--------
def division()
--------
--------
This can make it easier for us to work on the Python arithmetic function.
Numpy module
For projects, the industry uses this function for scientific computing.
Example
import numpy as np?
a = np.array([10,20,35])?
print(a)
Output
[10 20 35]
Django module
This module is used for web application and project terminology, and it is widely utilized in various sectors of the economy. Python allows us to build any kind of module to cut down on the effort and time needed in complex situations.
The module path search methods
The interpreter looks first to see if a built-in module with the name spam already exists before importing a module with the name spam. The list of system built-in modules contains the module names mentioned below with Python (a list of directory names, with the same syntax as the shell variable PATH).
How to import the module?
All the functions of one module can be imported into another using the import statement. For instance, we should think about whether importing a Python source file as a module into another source file will allow us to utilize the functions of that file.
Import math
Print (dir(math))
? Import ABC
Aliasing Module (importing a module with its alias name)
When importing a module, you can make an alias by using the keyword.
Thus, the crucial capability of renaming a module at import time is provided by Python.
The syntax for Alias Modules
Benefits of Python modules
?Python modules drawbacks.
Takeaways: