Modularity:
- In software (Modular Programming), large programs are broken into smaller, manageable sub-programs or functions.
- Each module handles one aspect of functionality, improving readability, debugging, and reusability.
Core Concepts of Python Modularity:
- Modules
- Packages
Import System
Module:
- A Python module is a file containing Python definitions and statements (such as functions, classes, and variables) with a .py extension.
It allows you to logically organize, reuse, and share your code across different programs.
Uses of modules:Code Reusability
Maintainability
Namespacing
Create a module:
- Save a file named function_demo.py With the following content
def add(no1, no2):
return no1 + no2
def subtract(no1, no2):
return no1 - no2
def multiply(no1, no2):
return no1 * no2
def divide(no1, no2):
return no1 // no2
developer = 'nimal anand'
Import the module:
- Use the import keyword in another Python file to use that code
import function_demo
result = function_demo.add(100,150)
print(result)
print(function_demo.developer)
print(type (function_demo))
Output:
250
nimal anand
<class:'module'>
The type() Function
- Returns the exact class type of an object. Example:
x = 10
print(type(x))
Output:
class 'int'
pycache:
- pycache is a directory created automatically by Python to store compiled bytecode (.pyc files).
Difference between file vs module:
duck typing language:
- Duck typing is a programming style where an object's suitability is determined by the presence of specific methods and properties rather than its actual class or explicit type inheritance.
ASCII:
- ASCII stands for American Standard Code for Information Interchange.
It is a system that gives a unique number from 0 to 127 to English letters, numbers, and symbols so computers can read text.
ISCII:ISCII stands for Indian Standard Code for Information Interchange.
It maps 256 total characters, blending standard English text compatibility with native Indic alphabets.

Top comments (0)