DEV Community

vishwa v
vishwa v

Posted on

Python-5(Module

Modularity:
It is the design which used to breaking down larger program into smaller program
In this Reusable sub-parts called modules.

Core concepts of Modularity

  • Modules
  • Packages
  • Import System

Module:
In Python, a module is simply a file that contains Python code — functions, classes, or variables — that you can reuse in other programs. It helps keep your code organized and avoids repetition.

Types of Modules
1.Built-in Modules:
Pre-installed with Python, no extra setup needed

import math
print(math.sqrt(25))   # Output: 5.0

Enter fullscreen mode Exit fullscreen mode

2.User-Defined Modules
Created by developers to organize reusable code.

A module is simply a .py file containing functions, variables, or classes.

Example: calc.py

import calc
print(calc.add(10, 5))   # Output: 15

Enter fullscreen mode Exit fullscreen mode

3.External (Third-Party) Modules
Developed by the community and installed using pip.

Examples:

NumPy → numerical computing

Pandas → data analysis

Requests → HTTP requests

Flask/Django → web development frameworks

import numpy as np
arr = np.array([1, 2, 3])
print(arr)   # Output: [1 2 3]

Enter fullscreen mode Exit fullscreen mode

duck typing language

Duck typing means a language decides what an object is based on what it can do, not what it is declared to be. Python is a classic duck-typed language: if an object has the right methods or attributes, it can be used, regardless of its actual class.

Top comments (0)