Interesting Presentation on Python Modules and packages
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. 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.
10. Thankyou
•1. 23BAI11216 Shresth Kumar
Jha
2. 23BAI11286 ISHAAN ROY
3. 23BCG10012 ARUNAVA
MUKHERJEE
4. 23BCG10054 DEEP NITIN
WATH