SlideShare a Scribd company logo
11
Most read
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:
Modules and Packages in Python Programming Language.pptx
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

PPTX
Interesting Presentation on Python Modules and packages
PDF
Using Python Libraries.pdf
PDF
Unit-2 Introduction of Modules and Packages.pdf
PPTX
Class 12 CBSE Chapter: python libraries.pptx
PDF
Python. libraries. modules. and. all.pdf
PDF
Modules and Packages in Python_Basics.pdf
PDF
Python libraries
Interesting Presentation on Python Modules and packages
Using Python Libraries.pdf
Unit-2 Introduction of Modules and Packages.pdf
Class 12 CBSE Chapter: python libraries.pptx
Python. libraries. modules. and. all.pdf
Modules and Packages in Python_Basics.pdf
Python libraries

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

PPSX
Modules and packages in python
PDF
Modules 101
PPTX
Modules and its usage in python for beginners
PPTX
package module in the python environement.pptx
PPTX
Docketrun's Python Course for beginners.pptx
PPTX
PYTHON FOR BEGINNERS (BASICS OF PYTHON)
PPTX
Functions in Python
PPTX
pythontraining-201jn026043638.pptx
PDF
Introduction To Python For Beginners
PPTX
Python module 3, b.tech 5th semester ppt
PPTX
PyCourse - Self driving python course
PPTX
Python training
PPTX
Python for Beginners
PPTX
Python Introduction
PDF
Python in a Nutshell, 4th Edition Alex Martelli
PDF
web programming UNIT VIII python by Bhavsingh Maloth
PPTX
Chapter - 4.pptx
PPTX
2024-25 TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
PPTX
Introduction to python lecture (1)
PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Modules and packages in python
Modules 101
Modules and its usage in python for beginners
package module in the python environement.pptx
Docketrun's Python Course for beginners.pptx
PYTHON FOR BEGINNERS (BASICS OF PYTHON)
Functions in Python
pythontraining-201jn026043638.pptx
Introduction To Python For Beginners
Python module 3, b.tech 5th semester ppt
PyCourse - Self driving python course
Python training
Python for Beginners
Python Introduction
Python in a Nutshell, 4th Edition Alex Martelli
web programming UNIT VIII python by Bhavsingh Maloth
Chapter - 4.pptx
2024-25 TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
Introduction to python lecture (1)
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Ad

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
madgavkar20181017ppt McKinsey Presentation.pdf
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
cuic standard and advanced reporting.pdf
GamePlan Trading System Review: Professional Trader's Honest Take
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Ad

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:
  • 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