Python Module
Python Module एक .py फ़ाइल होती है जिसमें functions, classes, variables तथा executable statements होते हैं। इसका उपयोग code को organize, reuse और maintain करने के लिए किया जाता है। इसे import keyword द्वारा किसी भी Python program में आसानी से उपयोग किया जा सकता है।
Features of Python Module
| ordered | characteristics | Description |
|---|---|---|
| 1 | Code Reusability | एक बार लिखा गया code कई programs में उपयोग किया जा सकता है। |
| 2 | Code Organization | बड़े program को छोटे-छोटे modules में बाँटा जा सकता है। |
| 3 | Easy Maintenance | किसी एक module में बदलाव करने से पूरा project बदलने की जरूरत नहीं होती। |
| 4 | Error Reduction | बार-बार code लिखने की आवश्यकता नहीं होती। |
| 5 | Better Readability | Program समझने में आसान हो जाता है। |
| 6 | Faster Development | पहले से बने modules का उपयोग करके जल्दी program बनाया जा सकता है। |
| 7 | Easy Sharing | Modules को दूसरे programmers के साथ साझा किया जा सकता है। |
Advantages of Python Module
- Code Reusability – एक बार लिखा गया code कई programs में दोबारा उपयोग किया जा सकता है।
- Easy Maintenance – Module में बदलाव करने पर पूरा program बदलने की आवश्यकता नहीं होती है।
- Better Code Organization – बड़े program को छोटे-छोटे modules में व्यवस्थित किया जा सकता है।
- Easy Debugging – Error को ढूँढना और ठीक करना आसान होता है।
- Team Work Support – अलग-अलग modules पर कई programmers एक साथ काम कर सकते हैं।
- Time Saving – पहले से बने modules का उपयोग करके विकास (development) का समय बचता है।
- Improved Readability – Code साफ, समझने योग्य और पढ़ने में आसान होता है।
Disadvantages of Python Module
- Import Error – गलत तरीके से module import करने पर error आ सकती है।
- Dependency Problem – एक module दूसरे module पर निर्भर हो सकता है।
- Execution Time – बहुत अधिक modules import करने से program शुरू होने में थोड़ा अधिक समय लग सकता है।
- Name Conflict – अलग-अलग modules में समान नाम के functions या variables होने पर भ्रम हो सकता है।
- File Management – बड़े projects में अधिक modules होने से उन्हें व्यवस्थित रखना कठिन हो सकता है।
- Version Compatibility – अलग-अलग versions के modules के कारण compatibility की समस्या हो सकती है।
- Learning Complexity – नए learners के लिए modules और imports को समझना शुरुआत में थोड़ा कठिन हो सकता है।
Types of Modules
1. Built-in Module
Built-in Module वे modules होते हैं जो Python के साथ पहले से उपलब्ध होते हैं। इन्हें अलग से install करने की आवश्यकता नहीं होती। इन्हें import keyword द्वारा सीधे उपयोग किया जाता है। उदाहरण: math, random, os, sys, datetime आदि।
Python Built-in Modules :-
| Ordered | Module | Use |
|---|---|---|
| 1 | math | Mathematical operations (गणितीय कार्य) |
| 2 | random | Random number generate करना |
| 3 | os | Operating System से संबंधित कार्य |
| 4 | sys | System information और Python interpreter से संबंधित कार्य |
| 5 | datetime | Date और Time को handle करना |
| 6 | time | Time delay और current time प्राप्त करना |
| 7 | calendar | Calendar से संबंधित कार्य |
| 8 | statistics | Mean, Median, Mode जैसी statistical calculations |
| 9 | string | String constants और string operations |
| 10 | re | Regular Expression (Pattern Matching) |
| 11 | json | JSON data को पढ़ना और लिखना |
| 12 | csv | CSV file को पढ़ना और लिखना |
| 13 | collections | Specialized data structures उपलब्ध कराना |
| 14 | itertools | Iterators बनाने और उपयोग करने के लिए |
| 15 | functools | Higher-order functions और decorators |
| 16 | pathlib | File और folder path को manage करना |
| 17 | shutil | File copy, move और delete करना |
| 18 | socket | Network communication (Client-Server Programming) |
| 19 | sqlite3 | SQLite database पर कार्य करना |
| 20 | tkinter | GUI (Graphical User Interface) application बनाना |
Module Import करने के तरीके
1. Import module
import math
print(math.pi)
2. Import Module as Alias
import math as m
print(m.sqrt(64))
Output
8.0
3. from Module import Function
from math import sqrt
print(sqrt(49))
Output
7.0
4. from Module import *
from math import *
print(sqrt(81))
print(pi)
Output
9.0
3.141592653589793
2. User Defined Module
User-defined Module वह Module होता है जिसे Programmer स्वयं बनाता है। यह एक .py फ़ाइल होती है जिसमें functions, classes, variables और Python code लिखा जाता है। इसे import करके अन्य Python programs में दोबारा उपयोग (reuse) किया जा सकता है।
User-defined Module बनाने के Steps
Step 1: mymodule.py नाम की फ़ाइल बनाएँ
def add(a, b):
return a + b
def sub(a, b):
return a - b
Step 2: main.py में Module Import करें
import mymodule
print("Addition =", mymodule.add(20, 10))
print("Subtraction =", mymodule.sub(20, 10))
Output
Addition = 30
Subtraction = 10
Advantages of User-defined Module
| Ordered | Advantages | Description |
|---|---|---|
| 1 | Code Reusability | एक बार लिखा गया code कई programs में दोबारा उपयोग किया जा सकता है। |
| 2 | Easy Maintenance | Module में बदलाव करने पर पूरा program बदलने की आवश्यकता नहीं होती। |
| 3 | Better Code Organization | बड़े program को छोटे-छोटे modules में व्यवस्थित किया जा सकता है। |
| 4 | Easy Debugging | Errors को ढूँढना और ठीक करना आसान होता है। |
| 5 | Time Saving | पहले से बने modules का उपयोग करके development का समय बचता है। |
| 6 | Team Work Support | अलग-अलग programmers अलग-अलग modules पर एक साथ कार्य कर सकते हैं। |
| 7 | Improved Readability | Code साफ, समझने योग्य और पढ़ने में आसान होता है। |
Python Library
Python Library कई Modules का collection होती है, जिसमें पहले से लिखे गए functions, classes और packages होते हैं। इसका उपयोग programming को easy, fast और effective बनाने के लिए किया जाता है। Library की सहायता से कम code में अधिक कार्य किए जा सकते हैं।
Features of Python Library
- Pre-written Code – Python Library में पहले से लिखा हुआ code उपलब्ध होता है, इसलिए programmer को बार-बार वही code लिखने की आवश्यकता नहीं होती।
- Code Reusability – एक ही Library का उपयोग कई अलग-अलग Python programs में बार-बार किया जा सकता है।
- Easy to Use – Libraries को
importkeyword की सहायता से आसानी से program में शामिल करके उपयोग किया जा सकता है। - Time Saving – पहले से बने हुए functions और classes उपलब्ध होने के कारण development का समय काफी बचता है।
- High Performance – अधिकांश Python Libraries optimized होती हैं, जिससे program तेज़ और अधिक कुशल (Efficient) तरीके से कार्य करता है।
- Wide Functionality – Python Libraries की सहायता से Data Analysis, Machine Learning, Web Development, Image Processing, Networking और GUI जैसे अनेक कार्य किए जा सकते हैं।
- Open Source – अधिकांश Python Libraries निःशुल्क (Free) और Open Source होती हैं, इसलिए कोई भी उन्हें उपयोग, संशोधित (Modify) और साझा (Share) कर सकता है।
Advantages of Python Libraries
- Development Time Saving – पहले से बने functions और classes होने के कारण program जल्दी तैयार हो जाता है।
- Code Reusability – एक ही Library का उपयोग कई अलग-अलग projects में बार-बार किया जा सकता है।
- Easy Programming – Complex tasks को कम code में आसानी से पूरा किया जा सकता है।
- High Performance – कई Libraries optimized होती हैं, जिससे program तेज़ और अधिक efficient चलता है।
- Reliable and Tested – अधिकांश Libraries अच्छी तरह से tested होती हैं, इसलिए उनमें errors की संभावना कम होती है।
- Wide Functionality – Data Analysis, Machine Learning, Web Development, Networking और Image Processing जैसे अनेक कार्यों के लिए Libraries उपलब्ध हैं।
- Open Source – अधिकांश Python Libraries निःशुल्क (Free) और Open Source होती हैं।
Disadvantages of Python Libraries
- Large Size – कुछ Libraries का आकार बड़ा होता है, जिससे अधिक storage की आवश्यकता होती है।
- Dependency Issues – एक Library दूसरी Libraries पर निर्भर हो सकती है, जिससे installation और management कठिन हो सकता है।
- Version Compatibility – अलग-अलग versions के कारण compatibility की समस्या आ सकती है।
- Learning Complexity – कुछ Libraries को सीखने और सही तरीके से उपयोग करने में समय लगता है।
- Performance Overhead – आवश्यकता से अधिक Libraries import करने पर program की performance प्रभावित हो सकती है।
- Security Risk – Third-party Libraries में कभी-कभी security vulnerabilities हो सकती हैं।
- Maintenance Issues – यदि Library का support या updates बंद हो जाएँ, तो project को maintain करना कठिन हो सकता है।
Python की Main Libraries
| NumPy | Array, Matrix और Mathematical Calculations के लिए किया जाता है | | import numpy as nparr = np.array([10,20,30])print(arr) |
| Pandas | Data Analysis, CSV/Excel Files और Data Frame बनाने के लिए किया जाता है | | import pandas as pddata={"Name":["Rahul"],"Age":[20]}df=pd.DataFrame(data)print(df) |
| Matplotlib | Line Chart, Bar Chart और Graph बनाने के लिए किया जाता है | | import matplotlib.pyplot as pltplt.plot([1,2,3],[4,5,6])plt.show() |
| Seaborn | Statistical Graphs और Attractive Charts बनाने के लिए किया जाता है | | import seaborn as snstips=sns.load_dataset("tips")sns.scatterplot(data=tips,x="total_bill",y="tip") |
| SciPy | Scientific Computing और Mathematical Problems हल करने के लिए किया जाता है | | from scipy import constantsprint(constants.pi) |
| Scikit-learn | Machine Learning Models बनाने के लिए किया जाता है | | from sklearn.linear_model import LinearRegressionmodel=LinearRegression() |
| TensorFlow | Artificial Intelligence और Deep Learning Applications बनाने के लिए किया जाता है | | import tensorflow as tfprint(tf.__version__) |
| Keras | Neural Network Models बनाने और Train करने के लिए किया जाता है | | from keras.models import Sequentialmodel=Sequential() |
| PyTorch | Deep Learning और AI Research के लिए किया जाता है | | import torchx=torch.tensor([1,2,3])print(x) |
| OpenCV | Image Processing, Face Detection और Video Processing के लिए किया जाता है | | import cv2img=cv2.imread("image.jpg")print(img.shape) |
| Pillow (PIL) | Image Resize, Crop और Rotate करने के लिए किया जाता है | | from PIL import Imageimg=Image.open("image.jpg")img.show() |
| Requests | Website और API से Data प्राप्त करने के लिए किया जाता है | | import requestsr=requests.get("https://example.com")print(r.status_code) |
| BeautifulSoup | Website के HTML Data को पढ़ने (Web Scraping) के लिए किया जाता है | | from bs4 import BeautifulSouphtml="<h1>Hello</h1>"soup=BeautifulSoup(html,"html.parser") |
| Tkinter | GUI (Desktop Application) बनाने के लिए किया जाता है | | import tkinter as tkroot=tk.Tk()root.mainloop() |
| SQLite3 | SQLite Database बनाने और Data Store करने के लिए किया जाता है | | import sqlite3con=sqlite3.connect("student.db") |
| Flask | Web Application और REST API बनाने के लिए किया जाता है | | from flask import Flaskapp=Flask(__name__) |
| Django | Large Web Applications बनाने के लिए किया जाता है | | import djangoprint(django.get_version()) |
| FastAPI | High-Speed REST APIs बनाने के लिए किया जाता है | | from fastapi import FastAPIapp=FastAPI() |
| Plotly | Interactive Graphs और Dashboards बनाने के लिए किया जाता है | | import plotly.express as pxfig=px.line(x=[1,2],y=[3,4]) |
| Pygame | 2D Games बनाने के लिए किया जाता है | | import pygamepygame.init() |
- इसे भी पढ़े : Python Operator in Hindi
- इसे भी पढ़े : Python file handling
- इसे भी पढ़े : Python OOPS in Hindi
- Python Full Course Roadmap 2026Python Introduction↓Python Installation & Setup↓Python Basics↓Variables & Data Types↓Operators↓Conditional Statements↓Loops↓Functions↓Data Structures↓File Handling↓Exception Handling↓Object Oriented Programming (OOP)↓Modules & Libraries↓Advanced Python↓Database Connectivity↓Web Development↓Data Science & AI↓Automation & Projects↓Python Developer
- What is Python in Hindi (Basic to advanced)Introduction and History Introduction for Python Python History Python Features Python Applications Applications Uses 1. Artificial Intelligence (AI) and Machine Learning Python का उपयोग AI models, Machine Learning algorithms, Chatbots, Face Recognition, Voice Assistant और Prediction systems बनाने के लिए किया जाता है। 2. Data Science and Data Analysis Python से बड़े datasets को analyze… Read more: What is Python in Hindi (Basic to advanced)
- Python Keywords in Hindi (easy to understand )Python Keywords में ऐसे special word होते हैं जिनका Python भाषा में पहले से एक Predefined meaning होता है। Python Interpreter इन words को पहचानता है और इनके अनुसार कार्य करता है। Example : No. Keyword हिंदी में अर्थ Uses (उपयोग) Syntax 1 False गलत False keywords का use Boolean False value के लिए किया… Read more: Python Keywords in Hindi (easy to understand )
- Python Variables in Hindi (Easy to understand)what is Variable Assigning Value to variable Source Code : Output : 5 Hello [2, 5, 9] Changing Variable’s Values Source Code : Output : 5Hello[4, 5, 8] Assigning Single Value to Multiple Variables Source Code : Output : HelloHelloHelloHello Assigning Value to Variable according to order Source Code : Output : 1H[1, 2] Variable… Read more: Python Variables in Hindi (Easy to understand)
- Python Data Types in Hindi (easy to understand)Python में Data Type यह बताता है कि किसी variable में किस प्रकार का data store है। Python में data type को manually declare नहीं करना पड़ता, Python interpreter value देखकर data type पहचान लेता है। Example : Number Python में Number Data Types का उपयोग संख्याओं (Numbers) को store और process करने के लिए… Read more: Python Data Types in Hindi (easy to understand)
