0% found this document useful (0 votes)
12 views

Daniyal Python

Uploaded by

Md Daniyal Islam
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Daniyal Python

Uploaded by

Md Daniyal Islam
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1

St. Xavier's College of Management and Technology


NAAC Accredited with B++ Grade(1st Cycle)
Digha-Aashiyana Road, Digha Ghat, Patna – 800011, Bihar

Topic : Module and Package


Subject : Python

Name : Md Daniyal Islam


Roll Number : 49
Department : BCA
Semester : 1

Under the guidance of Assistant Professor Supriya Mam


1

• Module refers to a file containing Python Statements


and definitions.
• We use modules to break down large programs into
small manageable and organized files.
Introduction to • A module can define functions, classes and variables.
Modules • These files have a .py extension and can be imported
into other Python scripts.
• Python has a large standard library that provides many
useful modules, such as math, random, and datetime.
1
1

Python has several built-in modules that can be used to


perform various tasks. These modules are pre-installed
with Python and can be imported into your code using
the import statement. Here are some commonly used
built-in modules in Python:
Using Built-in math - provides mathematical functions like sqrt(), sin(),
cos(), etc.
Modules random - generates random numbers and sequences.
datetime - provides classes for working with dates and
times.
os - provides a way of using operating system dependent
functionality like reading or writing to the file system.
1
 To create your own module in Python, you simply need to write
a Python file with the .py extension containing the functions or
variables you want to include in the module.
 For example, let's say you want to create a module called
"math_operations" that contains functions for basic
mathematical operations such as addition, subtraction,
multiplication, and division. You would create a new file called
"math_operations.py" and define the functions within it.
 Once you have defined your functions, you can import the
Creating Your module into your Python script using the import statement. For
Own Module example, if you want to use the addition function from the
math_operations module, you would write:
 import math_operations
 You can then call the addition function using the following
syntax:
 result = math_operations.addition(2, 3)
 This will assign the value of 5 to the variable "result".
1

 In Python, a package is a way to


organize related modules. It allows
you to group together modules that
have similar functionality and make
them easier to manage. Packages
can contain other packages, as well

Introduction as modules and even sub-packages.


 One of the benefits of using

to Packages packages is that it helps to avoid


naming conflicts. By placing related
modules in a package, you can give
them a common namespace, which
makes it less likely that you will
accidentally use the same name for
two different things.
In Python, modules and packages are used to organize code into reusable
and sharable components. Importing these modules and packages into
your code is a simple process that can be done in a few different ways.
Importing a Module Importing a Package
To import a module, you simply A package is a collection of related
use the 'import' keyword followed modules that are organized into a
Importing by the name of the module. For
example, to import the 'math'
directory structure. To import a package,
you use the 'import' keyword followed by
Modules and module, you would use the the name of the package. For example, to

Packages following code:


import math
import a package named 'mypackage',
you would use the following code:
Once the module is imported, you import mypackage
can use its functions and variables Once the package is imported, you can
in your code by prefixing them access its modules by using dot notation.
with the module name. For For example, to use a module named
example, to use the 'sqrt' function 'mymodule' that is part of the
from the 'math' module, you would 'mypackage' package, you would use the
use the following code: following code:
result = math.sqrt(25) result =
mypackage.mymodule.myfunction()
Modules and packages are your allies
for building organized, collaborative,
and scalable Python applications.

Conclusion

Simplify your Python development


journey with these powerful tools
10

 JEEVA JOSE(2016), 'INTRODUCTION TO COMPUTING


AND PROBLEM SOLVING WITH PYTHON'
 PYTHON DOCUMENTATION. (N.D.). "MODULES."
 AVAILABLE AT:
HTTPS://DOCS.PYTHON.ORG/3/TUTORIAL/MODULES.HTML
 PYTHON DOCUMENTATION. (N.D.). "PACKAGES."

Reference  AVAILABLE AT:


HTTPS://DOCS.PYTHON.ORG/3/TUTORIAL/MODULES.HTML#PAC
KAGES

 GEEKSFORGEEKS. (N.D.). "PYTHON MODULES."


 AVAILABLE AT:
HTTPS://WWW.GEEKSFORGEEKS.ORG/PYTHON-MODULES/
QUESTIONS

You might also like