SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
MODULES
IN PYTHON PROGRAMMING
MODULES
 A python modules can be defined as a python program file.
 It contains – functions, class or variables.
 Modules in Python provide us the flexibility to organize the code in a logical way.
 Example:
def myModule(name)
print(“Hi!”, name);
 Save the above code with <filename>.py
LOADING A MODULE IN PYTHON CODE
 Python provides 2 types of statements:
 Import Statement
 From-import Statement
IMPORT STATEMENT
 Import statement is used to import all the functionality of one module into another.
 We can import multiple modules with a single import statement, but a module is loaded once regardless
of the number of times.
 Syntax:
import module1, modeule2, . . . . , module n
 Example:
import file
name = input(“Enter your name:”)
file.displayMsg(name)
FROM-IMPORT STATEMENT
 It provides the flexibility to import only the specific attributes of a module.
 Syntax:
from <module-name> import <name1>, <name2> . . .
 Calculation.py
def sum(a,b):
return a + b
def mul(a,b):
return a * b
def div(a,b):
return a/b
EXAMPLE
 Myprogram.py
from calculation import sum #it will import only the sum() from calculation.py
a = int(input(“Enter the first number”))
b = int(input(“Enter the second number”))
print(“Sum = “, sum(a,b))
IMPORT AS STATEMENT [RENAMING A MODULE]
 Python provides us the flexibility to import some module with a specific name so that we can use this
name to use that module in python source file.
 Syntax:
import <module-name> as <specific-name>
 Example:
import calculation as cal;
a = int(input(“Enter first number”))
b = int(input(“Enter second number”))
print(“Sum = “, cal.sum(a,b))
DIR( ) FUNCTION
 The dir( ) function returns a sorted list of names defined in the passed module.
 This list contains all the sub-modules, variables and functions defined in this module.
 Example:
import json
list = dir(json)
print(list)
RELOAD( ) FUNCTION
 If you want to reload the already imported module to re-execute the top-level code, python provides us
the reload( ) function.
 Syntax:
reload(<module-name>)
 Example:
reload(calculation)
PYTHON PACKAGES
 The packages in python facilitate the developer with the application development environment by
providing a hierarichical directory structure where a package contains sub-packages, modules, and sub-
modules.
 The packages are used to categorize the application level code efficiently.
EXAMPLE OF PACKAGE
 Library management system which contains three sub-packages as Admin, Librarian, and student. The
sub-packages contain the python modules.

More Related Content

What's hot (20)

ODP
Python Modules
Nitin Reddy Katkam
 
PPTX
Packages In Python Tutorial
Simplilearn
 
PPTX
Functions in Python
Kamal Acharya
 
PPTX
Python-Functions.pptx
Karudaiyar Ganapathy
 
PPTX
classes and objects in C++
HalaiHansaika
 
PDF
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
PPTX
Data Structures in Python
Devashish Kumar
 
PDF
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
PPTX
Python: Modules and Packages
Damian T. Gordon
 
PPSX
python Function
Ronak Rathi
 
PPTX
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
PPTX
Pointers in c++
sai tarlekar
 
PPTX
Applets in java
Wani Zahoor
 
PDF
Set methods in python
deepalishinkar1
 
PPTX
Java(Polymorphism)
harsh kothari
 
PPTX
Functions in python slide share
Devashish Kumar
 
PPTX
Function C programming
Appili Vamsi Krishna
 
PPTX
Chapter 05 classes and objects
Praveen M Jigajinni
 
PPTX
Basics of Object Oriented Programming in Python
Sujith Kumar
 
PPTX
File Handling Python
Akhil Kaushik
 
Python Modules
Nitin Reddy Katkam
 
Packages In Python Tutorial
Simplilearn
 
Functions in Python
Kamal Acharya
 
Python-Functions.pptx
Karudaiyar Ganapathy
 
classes and objects in C++
HalaiHansaika
 
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Data Structures in Python
Devashish Kumar
 
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Python: Modules and Packages
Damian T. Gordon
 
python Function
Ronak Rathi
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
Pointers in c++
sai tarlekar
 
Applets in java
Wani Zahoor
 
Set methods in python
deepalishinkar1
 
Java(Polymorphism)
harsh kothari
 
Functions in python slide share
Devashish Kumar
 
Function C programming
Appili Vamsi Krishna
 
Chapter 05 classes and objects
Praveen M Jigajinni
 
Basics of Object Oriented Programming in Python
Sujith Kumar
 
File Handling Python
Akhil Kaushik
 

Similar to Modules in Python Programming (20)

PPTX
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
RoshanJoshuaR
 
PDF
Unit-2 Introduction of Modules and Packages.pdf
Harsha Patil
 
PDF
Python Modules
Soba Arjun
 
PPTX
Python for Beginners
DrRShaliniVISTAS
 
PDF
Using Python Libraries.pdf
SoumyadityaDey
 
PPTX
package module in the python environement.pptx
MuhammadAbdullah311866
 
PPT
Python modules
Shanmugapriya Dineshbabu
 
PDF
Python libraries
Prof. Dr. K. Adisesha
 
PPTX
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
 
PDF
Modules and Packages in Python_Basics.pdf
RavindraTambe3
 
PPTX
Modules and its usage in python for beginners
Mohammad Usman
 
PPTX
Unit 2function in python.pptx
vishnupriyapm4
 
PDF
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
PPTX
Interesting Presentation on Python Modules and packages
arunavamukherjee9999
 
PPTX
Chapter - 4.pptx
MikialeTesfamariam
 
PPTX
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal
 
PPTX
Functions_in_Python.pptx
krushnaraj1
 
PPTX
Python module 3, b.tech 5th semester ppt
course5325
 
PPTX
Class 12 CBSE Chapter: python libraries.pptx
AravindVaithianadhan
 
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
RoshanJoshuaR
 
Unit-2 Introduction of Modules and Packages.pdf
Harsha Patil
 
Python Modules
Soba Arjun
 
Python for Beginners
DrRShaliniVISTAS
 
Using Python Libraries.pdf
SoumyadityaDey
 
package module in the python environement.pptx
MuhammadAbdullah311866
 
Python modules
Shanmugapriya Dineshbabu
 
Python libraries
Prof. Dr. K. Adisesha
 
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
 
Modules and Packages in Python_Basics.pdf
RavindraTambe3
 
Modules and its usage in python for beginners
Mohammad Usman
 
Unit 2function in python.pptx
vishnupriyapm4
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
Interesting Presentation on Python Modules and packages
arunavamukherjee9999
 
Chapter - 4.pptx
MikialeTesfamariam
 
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal
 
Functions_in_Python.pptx
krushnaraj1
 
Python module 3, b.tech 5th semester ppt
course5325
 
Class 12 CBSE Chapter: python libraries.pptx
AravindVaithianadhan
 
Ad

Recently uploaded (20)

PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Ad

Modules in Python Programming

  • 2. MODULES  A python modules can be defined as a python program file.  It contains – functions, class or variables.  Modules in Python provide us the flexibility to organize the code in a logical way.  Example: def myModule(name) print(“Hi!”, name);  Save the above code with <filename>.py
  • 3. LOADING A MODULE IN PYTHON CODE  Python provides 2 types of statements:  Import Statement  From-import Statement
  • 4. IMPORT STATEMENT  Import statement is used to import all the functionality of one module into another.  We can import multiple modules with a single import statement, but a module is loaded once regardless of the number of times.  Syntax: import module1, modeule2, . . . . , module n  Example: import file name = input(“Enter your name:”) file.displayMsg(name)
  • 5. FROM-IMPORT STATEMENT  It provides the flexibility to import only the specific attributes of a module.  Syntax: from <module-name> import <name1>, <name2> . . .  Calculation.py def sum(a,b): return a + b def mul(a,b): return a * b def div(a,b): return a/b
  • 6. EXAMPLE  Myprogram.py from calculation import sum #it will import only the sum() from calculation.py a = int(input(“Enter the first number”)) b = int(input(“Enter the second number”)) print(“Sum = “, sum(a,b))
  • 7. IMPORT AS STATEMENT [RENAMING A MODULE]  Python provides us the flexibility to import some module with a specific name so that we can use this name to use that module in python source file.  Syntax: import <module-name> as <specific-name>  Example: import calculation as cal; a = int(input(“Enter first number”)) b = int(input(“Enter second number”)) print(“Sum = “, cal.sum(a,b))
  • 8. DIR( ) FUNCTION  The dir( ) function returns a sorted list of names defined in the passed module.  This list contains all the sub-modules, variables and functions defined in this module.  Example: import json list = dir(json) print(list)
  • 9. RELOAD( ) FUNCTION  If you want to reload the already imported module to re-execute the top-level code, python provides us the reload( ) function.  Syntax: reload(<module-name>)  Example: reload(calculation)
  • 10. PYTHON PACKAGES  The packages in python facilitate the developer with the application development environment by providing a hierarichical directory structure where a package contains sub-packages, modules, and sub- modules.  The packages are used to categorize the application level code efficiently.
  • 11. EXAMPLE OF PACKAGE  Library management system which contains three sub-packages as Admin, Librarian, and student. The sub-packages contain the python modules.