SlideShare a Scribd company logo
1 of 11
Understand ng Modules and
Packages n Python
An Overview of Python's Modular Programming
•How do modules help
you write clear and
focused code in Python?
Python lets you write code in small parts called
modules. You can use the ‘import’ statement to
combine modules easily. Modules help you write
clear and focused code. Python is good for making
big and clean software. Python modules make
your code easy tounderstand and work with.
What are Modules?
A Python module is a file containing
Python definitions and statements. A
module can define functions, classes, and
variables. A module can also include
runnable code. Grouping related code into a
module makes the code easier to
understand and use. It also makes the
code logically organized. The file name is
the module name with the suffix .py
appended.
Examples of common modules (e.g.,
math, random, datetime)
Creating and
Using
Modules
How to create a module
TO CREATE A MODULE, YOU JUST
NEED TO SAVE YOUR CODE IN A
FILE wITH THE .pY EXTENSION.
Importingmodulesin
Python
THEN YOU CAN IMpORT THE
MODULE IN ANOTHER FILE AND
USE THE FUNCTION:
Examples of Modules
6. json: Enables JSON encoding and decoding.
7.requests: Simplifies sending HTTP requests.
8. re: Supports regular expressions for pattern
matching.
9.csv: Facilitates reading and writing CSV files.
10.collections: Offers alternatives to built-in
types like dictionaries and lists.
1. mat: Provides mathematical functions.
2. os :Offers a way of using operating system-
dependent functionality.
3.sys: Provides access to some variables used
or maintained by the Python interpreter.
4. datetime: Allows manipulation of dates and
times.
5. random: Implements pseudo-random number
generators.
.
What are packages?
•A package is a container that contains various
functions to perform specific tasks. For
example, the math package includes the sqrt()
function to perform the square root of a
number.
•While working on big projects, we have to deal
with a large amount of code, and writing
everything together in the same file will make
our code look messy. Instead, we can separate
our code into multiple files by keeping the
related code together in packages.
•Now, we can use the package whenever we
need it in our projects. This way we can also
reuse our code.
CreatingandUsing
Packages
•Create a new folder
named D:MyApp .
•Inside MyApp ,
create a subfolder
with the name
'mypackage'.
•Create anfunctions.py file
in the mypackage folder.
•Usinga Python-aware
editor like IDLE,
create modules greet.py
and functions.py with
the following code:
Namespaceand
Scope
• A namespaceisacollectionofnamesthatrefertoobjects
• Pythonhasdifferenttypesofnamespaces,suchasbuilt-in, global, local,and
enclosing
• Thebuilt-innamespacecontainsthenamesofthebuilt-inobjects,suchasint,
str, print,etc.
• Theglobalnamespacecontainsthenamesoftheobjectsdefinedatthetoplevelof
amodule
• Thelocalnamespacecontainsthenamesoftheobjectsdefinedinsideafunctionora
class
• A scopeistheregionofcodewhereanameisvisibleandcanbeaccessed
• Pythonhasfourlevelsofscope:local,enclosing,global, andbuilt-in(LEGB)
• Thelocalscopeistheinnermostscopeandcontainsthenamesdefinedin
thecurrentfunctionorclass
• Theenclosingscopeisthescopeoftheenclosingfunctionorclass,ifany
• Theglobalscopeisthescopeofthecurrentmodule
In conclusion,
understanding and
harnessing the power of
modules and packages in
Python is paramount for
building scalable,
organised, and
maintainable code. As
we've explored, modules
encapsulate code,
making it reusable and
preventing naming
conflicts. Packages take
this a step further,
providing a structured
way to organise modules
into a hierarchical
directory structure.
• Conclusion
By adopting modular
programming practices,
developers can enhance
code readability, promote
code reuse, and streamline
collaboration within
projects. As you continue
your Python journey,
remember the significance
of creating well-designed
modules and packages, as
they form the backbone of
robust and efficient
software development.
Thankyou
•1. 23BAI11216 Shresth Kumar
Jha
2. 23BAI11286 ISHAAN ROY
3. 23BCG10012 ARUNAVA
MUKHERJEE
4. 23BCG10054 DEEP NITIN
WATH

More Related Content

Similar to Modules and Packages in Python Programming Language.pptx

Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and PackagesDamian T. Gordon
 
Python data structures and modules
Python data structures and modulesPython data structures and modules
Python data structures and modulesMohamed Essam
 
20120314 changa-python-workshop
20120314 changa-python-workshop20120314 changa-python-workshop
20120314 changa-python-workshopamptiny
 
PyCourse - Self driving python course
PyCourse - Self driving python coursePyCourse - Self driving python course
PyCourse - Self driving python courseEran Shlomo
 
2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptxMohamed Essam
 
Introduction to package manager
Introduction to package managerIntroduction to package manager
Introduction to package manageryashobantabai
 
Introduction to Python Programming Language For Artificial Intelligence
Introduction to Python Programming Language For Artificial IntelligenceIntroduction to Python Programming Language For Artificial Intelligence
Introduction to Python Programming Language For Artificial Intelligencesaraahmed870035
 
Python_Introduction&DataType.pptx
Python_Introduction&DataType.pptxPython_Introduction&DataType.pptx
Python_Introduction&DataType.pptxHaythamBarakeh1
 
Modules 101
Modules 101Modules 101
Modules 101gjcross
 
Python for katana
Python for katanaPython for katana
Python for katanakedar nath
 
Python Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxPython Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxMohammad300758
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1Ahmet Bulut
 
Reversingobfuscatedpythonapplications dropbox-140819110311-phpapp01
Reversingobfuscatedpythonapplications dropbox-140819110311-phpapp01Reversingobfuscatedpythonapplications dropbox-140819110311-phpapp01
Reversingobfuscatedpythonapplications dropbox-140819110311-phpapp01Wajhi Ul Hassan Naqvi
 

Similar to Modules and Packages in Python Programming Language.pptx (20)

Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Python data structures and modules
Python data structures and modulesPython data structures and modules
Python data structures and modules
 
20120314 changa-python-workshop
20120314 changa-python-workshop20120314 changa-python-workshop
20120314 changa-python-workshop
 
PyCourse - Self driving python course
PyCourse - Self driving python coursePyCourse - Self driving python course
PyCourse - Self driving python course
 
2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx
 
Introduction to package manager
Introduction to package managerIntroduction to package manager
Introduction to package manager
 
Introduction to Python Programming Language For Artificial Intelligence
Introduction to Python Programming Language For Artificial IntelligenceIntroduction to Python Programming Language For Artificial Intelligence
Introduction to Python Programming Language For Artificial Intelligence
 
Python Course In Chandigarh
Python Course In ChandigarhPython Course In Chandigarh
Python Course In Chandigarh
 
Python_Introduction&DataType.pptx
Python_Introduction&DataType.pptxPython_Introduction&DataType.pptx
Python_Introduction&DataType.pptx
 
Modules 101
Modules 101Modules 101
Modules 101
 
Chapter - 4.pptx
Chapter - 4.pptxChapter - 4.pptx
Chapter - 4.pptx
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Python for katana
Python for katanaPython for katana
Python for katana
 
Python for Delphi Developers - Part 2
Python for Delphi Developers - Part 2Python for Delphi Developers - Part 2
Python for Delphi Developers - Part 2
 
Python Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxPython Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptx
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
 
Ad507
Ad507Ad507
Ad507
 
Bp301
Bp301Bp301
Bp301
 
C- language Lecture 8
C- language Lecture 8C- language Lecture 8
C- language Lecture 8
 
Reversingobfuscatedpythonapplications dropbox-140819110311-phpapp01
Reversingobfuscatedpythonapplications dropbox-140819110311-phpapp01Reversingobfuscatedpythonapplications dropbox-140819110311-phpapp01
Reversingobfuscatedpythonapplications dropbox-140819110311-phpapp01
 

Recently uploaded

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

Modules and Packages in Python Programming Language.pptx

  • 1. Understand ng Modules and Packages n Python An Overview of Python's Modular Programming
  • 2. •How do modules help you write clear and focused code in Python? Python lets you write code in small parts called modules. You can use the ‘import’ statement to combine modules easily. Modules help you write clear and focused code. Python is good for making big and clean software. Python modules make your code easy tounderstand and work with.
  • 3. What are Modules? A Python module is a file containing Python definitions and statements. A module can define functions, classes, and variables. A module can also include runnable code. Grouping related code into a module makes the code easier to understand and use. It also makes the code logically organized. The file name is the module name with the suffix .py appended. Examples of common modules (e.g., math, random, datetime)
  • 4. Creating and Using Modules How to create a module TO CREATE A MODULE, YOU JUST NEED TO SAVE YOUR CODE IN A FILE wITH THE .pY EXTENSION. Importingmodulesin Python THEN YOU CAN IMpORT THE MODULE IN ANOTHER FILE AND USE THE FUNCTION:
  • 5. Examples of Modules 6. json: Enables JSON encoding and decoding. 7.requests: Simplifies sending HTTP requests. 8. re: Supports regular expressions for pattern matching. 9.csv: Facilitates reading and writing CSV files. 10.collections: Offers alternatives to built-in types like dictionaries and lists. 1. mat: Provides mathematical functions. 2. os :Offers a way of using operating system- dependent functionality. 3.sys: Provides access to some variables used or maintained by the Python interpreter. 4. datetime: Allows manipulation of dates and times. 5. random: Implements pseudo-random number generators. .
  • 6. What are packages? •A package is a container that contains various functions to perform specific tasks. For example, the math package includes the sqrt() function to perform the square root of a number. •While working on big projects, we have to deal with a large amount of code, and writing everything together in the same file will make our code look messy. Instead, we can separate our code into multiple files by keeping the related code together in packages. •Now, we can use the package whenever we need it in our projects. This way we can also reuse our code.
  • 7. CreatingandUsing Packages •Create a new folder named D:MyApp . •Inside MyApp , create a subfolder with the name 'mypackage'. •Create anfunctions.py file in the mypackage folder. •Usinga Python-aware editor like IDLE, create modules greet.py and functions.py with the following code:
  • 8.
  • 9. Namespaceand Scope • A namespaceisacollectionofnamesthatrefertoobjects • Pythonhasdifferenttypesofnamespaces,suchasbuilt-in, global, local,and enclosing • Thebuilt-innamespacecontainsthenamesofthebuilt-inobjects,suchasint, str, print,etc. • Theglobalnamespacecontainsthenamesoftheobjectsdefinedatthetoplevelof amodule • Thelocalnamespacecontainsthenamesoftheobjectsdefinedinsideafunctionora class • A scopeistheregionofcodewhereanameisvisibleandcanbeaccessed • Pythonhasfourlevelsofscope:local,enclosing,global, andbuilt-in(LEGB) • Thelocalscopeistheinnermostscopeandcontainsthenamesdefinedin thecurrentfunctionorclass • Theenclosingscopeisthescopeoftheenclosingfunctionorclass,ifany • Theglobalscopeisthescopeofthecurrentmodule
  • 10. In conclusion, understanding and harnessing the power of modules and packages in Python is paramount for building scalable, organised, and maintainable code. As we've explored, modules encapsulate code, making it reusable and preventing naming conflicts. Packages take this a step further, providing a structured way to organise modules into a hierarchical directory structure. • Conclusion By adopting modular programming practices, developers can enhance code readability, promote code reuse, and streamline collaboration within projects. As you continue your Python journey, remember the significance of creating well-designed modules and packages, as they form the backbone of robust and efficient software development.
  • 11. Thankyou •1. 23BAI11216 Shresth Kumar Jha 2. 23BAI11286 ISHAAN ROY 3. 23BCG10012 ARUNAVA MUKHERJEE 4. 23BCG10054 DEEP NITIN WATH