Chapter 13 : Python Libraries
Advanced Python Programmer कम समय मे ही बडे - बडे Python Projects create कर देते है जिससे उनके Time की बचत होती है छोटे Logics लिखने पडते है | हमने इस Chapter को इसलिए Add किया है ताकि आप भी Python Language की मदद से बडे - बडे Projects को कम Time मे सरलता से Create कर सके | इस Chapter मे 1. Built In Libraries , 2. Third Party Libraries जैसे Topics को add किया गया है | Chapter के सभी Concepts को मजबूत बनाने के लिए Site पर Available Python Libraries Chapter से संबंधित Practice sets , Test को भी जरूर Attempt करे |
Introduction To Python Libraries
Python एक high-level Programming language है , जिसका उपयोग gernal purpose के works के लिए किया जाता है |
Python world Famous languages मे से एक है , लेकिन python language की सबसे बड़ी शक्ति Python Language
की Libraries है | Python की यही खूबी Python Language को दूसरी languages से अलग बनाती है | Python language
मे हर काम को करने के लिए कोई library उपलब्ध है | Libraries मे पहले से ही
code , methods , Functions , clasess etc. create किए हुए होते है | libraries के उपयोग से Coders को
काम करने मे आसानी होती है | Python मे किसी library को कुछ ऐसे import किया जाता है |
import libraryname
इस chapter मे libraries का उपयोग क्यों करे , libraries कितने तरह
की होती है , libraries का उपयोग क्यों करे आदि को समझाया गया है |
Advantages Of Libraries
1. Time Saving : Python Libraries पहले से ही create की हुई होती है , इसलिए हमे केवल इनका उपयोग
करना होता है , इसलिए Libraries के उपयोग से Time की बचत होती है |
2. code size : अगर हम libraries का उपयोग नही करते है तो normal है कि Programs लिखते Time codes बडे
होगे , लेकिन libraries के उपयोग से codes का size कम हो जाती है |
3. code speed : pandas जैसी libraries को c language मे बनाया गया है , इसलिए libraries से लिखे गए
Programs की speed increase होती है |
4. updation : Python की libraries लगातार update होती रहती है जिससे python developer को
libraries मे new feature मिलते रहते है |
5. Open-Source : Python libraries लगभग Open-Source है | चाहे वो library Built In हो या
Third party
Types Of Libraries
Python language मे Python libraries को mainly दो parts मे devide किया गया है | Built in libraries
और third party libraries
Built In Libraries : Built In Libraries वो libraries होती है | जो python के साथ installed हुई आती है | इन
libraries को
अलग से install करने की जरूत नही होती है | math library , datetime library , Random library etc. कुछ
Built In libraries के उदाहरण है |
Third party library : Third Party Libraries वो libraries होती है | जो python के साथ नही आती है
यानि की Third party libraries के उपयोग के लिए इन libraries को अलग से install किया जाता है |
ये libraries बाहरी किसी developer या company के दवारा create की हुई होती है | request , Django , Flask etc.
कुछ Third-Party libraries है |
Python मे Third-Party libraries को pip Command के उपयोग से install किया जाता है | एक
pip command कुछ ऐसी होती है |
pip install numpy
इस command को cmd मे चलाने पर numpy library install हो जायेगी |
Diffrence Between Built In and Third-Party library
| Base | Built In library | Third Party library |
|---|---|---|
| 3. Meaning | Python के साथ installed हुई आती है | | अलग से install करनी पडती है | |
| 2. Installation | Install करने की जरूत ही नही | pip command से install की जाती है | |
| 3. Developer | Python की team ने बनाई है | | बाहरी developer या company बनाती है | |
| 4. speed | speed fast होती है | | library पर depand करती है | |
| 5. updation Process | अपने आप python version के साथ update हो जाती है | | pip command के उपयोग से update करनी पडती है | |
PIP
Python Programming Language हो या C , C++ जैसी कोई और Programming Language सभी Language मे Third Party Libraries का उपयोग किया जाता है | Third Party Libraries को install करने के लिए PIP Command का उपयोग किया जाता है | PIP का पूरा नाम Pip Installs Packages है | PIP Python का package manager होता है , जिसकी मदद से हम आसानी से libraries को install, update और remove कर सकते हैं | PIP Command Directly Internet से Libraries को System मे install करता है | नीचे कुछ PIP Commands दि गई है |
PIP Commands
pip --version
PIP Command का उपयोग करने से पहले Programer को check कर लेना चाहिए की PIP computer मे installed है या नही ताकि कोई library install update करने मे Time खराब न हो | ऊपर दि गई Command को Python Terminal मे run करने से हमे पता चलता है कि PIP हमारे Computer System मे Installed है या नही अगर PIP install नही है तो PIP का उपयोग करने के लिए PIP को install करना पडता है |
pip list
ऊपर दि गई Command को Python Terminal मे run करने से हम पता कर सकते है कि अब तक हमारे Computer System मे कुल कितनी Libraries Intalled हुई है | Beginer को Third Party Libraries का उपयोग करने से पहले हमेशा पता कर लेना चाहिए कि जिस library का उपयोग वो कर रहा वो computer मे installed है या नही ऐसे Programer आने वाले errors को handle कर सकता है |
pip install --upgrade pandas
जब किसी library मे new features add किए जाते है | तब हमे उस library को update करने की जरूरत होती है ताकि हम उस library का उपयोग कर सके | ऊपर दि गई Command को Python Terminal मे run करने से Computer System मे installed Library को Update किया जा सकता है |
pip uninstall numpy
किसी Project को पूरा करने के बाद उस Project से संबंधित Computer System installed Library को Programmer uninstall कर देता है क्योंकि अब उस Library की Programmer को जरूरत नही है | ऊपर दि गई Command को Python Terminal मे run करने से Computer System मे Installed library को uninstall किया जा सकता है |
Third Party Libraries
नीचे कुछ महत्वपूर्ण Third Party Libraries को विस्तार मे समझाया गया है |
requests library
request library को केनेथ रिट्ज़ ने 14 फरवरी 2011 को विकसित किया था | request एक third Party library है जिसका उपयोग किसी websites से data लेने data upload करने के लिए किया जाता है | request library को “HTTP for Humans” के नाम से भी जाना जाता है | request library को उपयोग करने के लिए इस library को अलग से install करना पडता है | request library के उपयोग से किसी webpage का data लेने का code नीचे दिया गया है |
1import requests 2response = requests.get("https://example.com")
Code Explanation
इस code को python मे run करने पर output मे दिए गए webpage का सारा content output मे आ जाएगा |
response = > response नाम का एक variable create किया गया है |
requests.get("https://example.com") = > ("https://example.com") webpage का सारा contect response
variable मे store किया गया है |
|
requests library का उपयोग कब करे |
1. जब आपको किसी webpage पर कोई data भेजना हो |
2. किसी webpage से data लेना हो |
3. जब header , cookies , tokens उपयोग करने हो |
4. जब कोई file download करनी हो |
5. जब काम आसान बनाना हो |
Django library
Django को एड्रियान होलोवेटी और साइमन विलिसन ने विकसित किया था | Django library को 2003 मे विकसित किया गया था | Django library को Django web framework के नाम से भी जाना जाता है | Django python की एक बहुत ही विशाल Library है जिसका उपयोग python के साथ websites को create करने के लिए किया जाता है | Django का उपयोग करने पर coding कम होती है और websites beautiful बनती है | Django library का उपयोग करना free है , यानि Django web framework Open-Source है | Django library को python मे pip install django command से install किया जाता है |
Django कहाँ उपयोग होता है?
Social Media Websites को बनाने ,
E-Commerce Sites (shopping sites) को बनाने ,
Education Platforms को बनाने ,
Blog Websites को बनाने ,
API Development etc. को विकसित करने मे django web framework का उपयोग किया जाता है |
Django का उपयोग क्यों करे ?
1. Django के उपयोग से बहुत fast Development की जा सकती है , इसलिए Websites को fast create करने के लिए Django का
उपयोग करे |
2. Django Mysql , SQLite etc. जैसे softwares के उपयोग से खुद data store कर सकता है , इसलिए Websites के data
को store करने के लिए Django का
उपयोग करे |
3. बडे - बडे Projects को Handle करने के लिए Django का उपयोग करे |
4. Django मे admin panel बनाने की जरूत ही नही Django खुद से create करके देता है |
5. Django कई सुरक्षा features पहले से देता है और आपकी वेबसाइट को सामान्य खतरों से बचाता है।
NOTE : Django एक web Framework है जिसका उपयोग python के साथ websites को create करने के लिए किया
जाता
है , इसलिए Django को अलग से सिखना पडता है |
Pygame library
जैसा की पहले ही बताया गया है कि python मे हर लगभग हर काम के लिए libraries है | games को बनाने के लिए भी Python मे एक library है जिसका नाम है - Pygame | Pygame library के उपयोग से 2d games create किए जा सकते है | Pygame library को पीट शिनर्स since 2000 मे बनाया | Pygame एक Third-Party gaming library है , इसलिए इस library के उपयोग के लिए इस library को pip की help से install किया जाता है |
Pygame क्यों उपयोग किया जाता है ?
1. Pygame library Begginers के सिखने मे सरल है , इसलिए Begginers game बनाने की starting Pygame library
से ही करते है |
2. Pygame library के उपयोग से 2d games easyly create किए जा सकते है |
3. games बनाने के लिए Pygame library free है , इसलिए Programmers Pygame का अधिक उपयोग करते है |
4. Pygame से coding skill, logic और creative thinking बढ़ती है।
5. Pygame library को learn करना easy है |
6. Pygame library के उपयोग से Snake Game ,
Flappy Bird,
Car Racing Game,
Space Shooter,
Ping Pong Game etc. जैसे games बनाना easy है |
नीचे एक pygame से simple game बनाया गया है | इस game मे
एक काली screen बनती है फिर
एक लाल बॉल बनती है और bole चारों तरफ bounce करती रहती है
1import pygame 2pygame.init() 3screen = pygame.display.set_mode((500, 400)) 4x, y = 50, 50 5dx, dy = 3, 3 6run = True 7while run: 8 for e in pygame.event.get(): 9 if e.type == pygame.QUIT: run = False 10 x += dx 11 y += dy 12 if x < 0 or x > 480: dx = -dx 13 if y < 0 or y > 380: dy = -dy 14 screen.fill((0,0,0)) 15 pygame.draw.circle(screen, (255,0,0), (x,y), 20) 16 pygame.display.update() 17pygame.quit()
Numpy library
NumPy (Numerical Python) Python की एक powerful library है जिसका इस्तेमाल गणित, data analysis, machine learning, data science और scientific calculations में किया जाता है | NumPy को इतनी ज़्यादा importance इसलिए मिलती है क्योंकि यह बहुत तेज़, memory efficient और large data को आसानी से handle कर सकती है |
NumPy क्या है और यह क्या करता है?
- तेज़ कैलकुलेशन: यह बहुत बड़े नंबर्स और डेटा को बहुत तेज़ी से प्रोसेस करता है |
- मैथ्स और साइंस: इसकी मदद से मुश्किल गणितीय (Mathematical) और वैज्ञानिक कैलकुलेशन आसान हो जाते हैं |
- मैट्रिक्स और एरे (Arrays): यह डेटा को रो (Rows) और कॉलम (Columns) में व्यवस्थित करके उन पर काम करता है |
- डेटा का आकार बदलना: यह बड़े डेटा का शेप बदलने (Reshape) और उसके किसी खास हिस्से को काटने (Slice) में मदद करता है |
- मशीन लर्निंग (Machine Learning): एआई (AI) और मशीन लर्निंग में डेटा को स्टोर और प्रोसेस करने के लिए यह सबसे ज़रूरी टूल है |
NumPy कहाँ-कहाँ उपयोग होता है?
- Data Science में: बड़े और जटिल Data को Analyze और Clean करने के लिए |
- Machine Learning में: Algorithms को Train करने और Data को Store करने के लिए |
- Deep Learning में: Neural Networks के अंदर Matrices (मैट्रिक्स) की Calculations करने के लिए |
- Statistics (सांख्यिकी) में: Data का Mean, Median और Standard Deviation जैसे Calculations निकालने के लिए |
- Image Processing में: डिजिटल इमेजेस (Images) को Pixels के रूप में Read और Modify करने के लिए |
- Scientific Research में: Physics, Chemistry और Biology से जुड़े मुश्किल Mathematical Models बनाने के लिए |
- Finance Modeling में: स्टॉक मार्केट (Stock Market) के ट्रेंड्स और रिस्क (Risk) को Analyze करने के लिए |
नीचे Numpy Library का एक सरल Python Code दिया गया है जो NumPy का उपयोग करके एक Array (नंबर्स की लिस्ट) बनाता है और उस पर गणितीय गणना (Mathematical Calculation) करता है |
1 import numpy as np 2 arr = np.array([1, 2, 3, 4]) 3 print(arr) 4 print(arr * 2)
code explanation
import numpy as np = > numpy library को import किया गया है |
arr = np.array([1, 2, 3, 4]) = > arr नाम का एक variable create किया गया है जिसमे
एक array का data store है |
print(arr) = > ये print() screen पर arr variable मे stored value को display करता है |
print(arr * 2) = > ये print() function arr variable को दो बार display करता है |
Emoji
यह PyPI (Python Package Index) पर उपलब्ध एक लोकप्रिय लाइब्रेरी है जो unicode emojizes को सपोर्ट करती है | sentences मे emojizes को लगाने के लिए emoji module file का उपयोग किया जाता है | emoji module मे बहुत सारे emojizes है | नीचे एक emoji library का Python Code दिया गया है |
1import emoji 2print(emoji.emojize("I love python : snake:"))
I love python 🐍
code explanation
import emoji = > emoji module file को import किया गया है |
print(emoji.emojize("I love python : snake:")) = > ये print() function screen पर display
emoji Library से snake नाम के
emoji को display करता है |
You have completed This Chapter ! 🎉
Now you can choose any one of the following options to test your knowledge :
Help Center
Users and we all help you together .