Movatterモバイル変換


[0]ホーム

URL:


Uploaded bysambitmandal
PPTX, PDF3,844 views

Modules in Python Programming

The document explains Python modules, which are program files that encapsulate functions, classes, or variables, enabling logical code organization. It describes how to import modules using import and from-import statements and how to use the import as feature to rename modules. Additionally, it covers the dir() and reload() functions for managing modules and introduces Python packages for organizing code in a hierarchical structure.

Related topics:

Embed presentation

Downloaded 33 times
MODULESIN 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 regardlessof the number of times. Syntax:import module1, modeule2, . . . . , module n Example:import filename = 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.pydef sum(a,b):return a + bdef mul(a,b):return a * bdef div(a,b):return a/b
EXAMPLE Myprogram.pyfrom calculation import sum #it will import only the sum() from calculation.pya = 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 thisname 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 jsonlist = dir(json)print(list)
RELOAD( ) FUNCTION If you want to reload the already imported module to re-execute the top-level code, python provides usthe reload( ) function. Syntax:reload(<module-name>) Example:reload(calculation)
PYTHON PACKAGES The packages in python facilitate the developer with the application development environment byproviding 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. Thesub-packages contain the python modules.

Recommended

PPTX
Python Flow Control
PPSX
Modules and packages in python
ODP
Python Modules
PDF
Python libraries
PPT
Python Dictionaries and Sets
PDF
Python programming : List and tuples
PDF
Python tuples and Dictionary
PPTX
Python Functions
PPTX
File Handling Python
PPTX
control statements in python.pptx
PDF
Datatypes in python
PPTX
Functions in python
PDF
Arrays in Java
PDF
Class and Objects in Java
PPTX
Data Structures in Python
PPTX
STRINGS IN PYTHON
PDF
Python tuple
PPTX
Python-Functions.pptx
PPTX
Iterarators and generators in python
PPT
1.python interpreter and interactive mode
PPTX
Data types in python
PPT
Python List.ppt
PDF
Python programming : Control statements
PPT
Input and output in C++
PDF
Python programming : Files
PDF
Python set
PPTX
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
PDF
Unit-2 Introduction of Modules and Packages.pdf

More Related Content

PPTX
Python Flow Control
PPSX
Modules and packages in python
ODP
Python Modules
PDF
Python libraries
PPT
Python Dictionaries and Sets
PDF
Python programming : List and tuples
PDF
Python tuples and Dictionary
Python Flow Control
Modules and packages in python
Python Modules
Python libraries
Python Dictionaries and Sets
Python programming : List and tuples
Python tuples and Dictionary

What's hot

PPTX
Python Functions
PPTX
File Handling Python
PPTX
control statements in python.pptx
PDF
Datatypes in python
PPTX
Functions in python
PDF
Arrays in Java
PDF
Class and Objects in Java
PPTX
Data Structures in Python
PPTX
STRINGS IN PYTHON
PDF
Python tuple
PPTX
Python-Functions.pptx
PPTX
Iterarators and generators in python
PPT
1.python interpreter and interactive mode
PPTX
Data types in python
PPT
Python List.ppt
PDF
Python programming : Control statements
PPT
Input and output in C++
PDF
Python programming : Files
PDF
Python set
Python Functions
File Handling Python
control statements in python.pptx
Datatypes in python
Functions in python
Arrays in Java
Class and Objects in Java
Data Structures in Python
STRINGS IN PYTHON
Python tuple
Python-Functions.pptx
Iterarators and generators in python
1.python interpreter and interactive mode
Data types in python
Python List.ppt
Python programming : Control statements
Input and output in C++
Python programming : Files
Python set

Similar to Modules in Python Programming

PPTX
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
PDF
Unit-2 Introduction of Modules and Packages.pdf
PDF
Python Modules
PPTX
Python for Beginners
PDF
Using Python Libraries.pdf
PPTX
package module in the python environement.pptx
PPT
Python modules
PPTX
Modules and Packages in Python Programming Language.pptx
PPTX
Functions in Python
PDF
class 12 Libraries in dfbdsbsdbdfbdfdfdf.pdf
PDF
Modules and Packages in Python_Basics.pdf
PPTX
Modules and its usage in python for beginners
PPTX
Unit 2function in python.pptx
PDF
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
PPTX
Interesting Presentation on Python Modules and packages
PPTX
Chapter - 4.pptx
PPTX
Functions_in_Python.pptx
PPTX
CLASS-11 & 12 ICT PPT Functions in Python.pptx
PPTX
Python module 3, b.tech 5th semester ppt
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
Unit-2 Introduction of Modules and Packages.pdf
Python Modules
Python for Beginners
Using Python Libraries.pdf
package module in the python environement.pptx
Python modules
Modules and Packages in Python Programming Language.pptx
Functions in Python
class 12 Libraries in dfbdsbsdbdfbdfdfdf.pdf
Modules and Packages in Python_Basics.pdf
Modules and its usage in python for beginners
Unit 2function in python.pptx
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Interesting Presentation on Python Modules and packages
Chapter - 4.pptx
Functions_in_Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptx
Python module 3, b.tech 5th semester ppt

Recently uploaded

PDF
Risk Management and Regulatory Compliance - by Ms. Oceana Wong
PPTX
What are New Features in Purchase _Odoo 18
PPTX
Elderly in India: The Changing Scenario.pptx
 
PDF
Multimodal and Multimedia AI - by Ms. Oceana Wong
PPTX
Physical education notes class ncert 12th
PPTX
Time Series Analysis - Meaning, Definition, Components and Application
PDF
Conferencia de Abertura_Virgilio Almeida.pdf
PDF
Deep Research and Analysis - by Ms. Oceana Wong
PDF
UGC NET Paper 1 Syllabus | 10 Units Complete Guide for NTA JRF
PDF
CXC-AD Associate Degree Handbook (Revised)
PPTX
Time Series Analysis - Method of Simple Moving Average 3 Year and 4 Year Movi...
PPTX
DEPED MEMORANDUM 089, 2025 PMES guidelines pptx
PDF
Agentic AI and AI Agents 20251121.pdf - by Ms. Oceana Wong
PDF
1. Doing Academic Research: Problems and Issues, 2. Academic Research Writing...
PPTX
Anatomy of the eyeball An overviews.pptx
PPTX
Masterclass on Cybercrime, Scams & Safety Hacks.pptx
PDF
Cattolica University - Lab Generative and Agentic AI - Mario Bencivinni
PPTX
Finals - History and Geography Quiz - Around the World in 80 Questions - IITK
PDF
বাংলাদেশ অর্থনৈতিক সমীক্ষা - ২০২৫ with Bookmark.pdf
PPTX
Time Series Analysis - Weighted (Unequal) Moving Average Method
Risk Management and Regulatory Compliance - by Ms. Oceana Wong
What are New Features in Purchase _Odoo 18
Elderly in India: The Changing Scenario.pptx
 
Multimodal and Multimedia AI - by Ms. Oceana Wong
Physical education notes class ncert 12th
Time Series Analysis - Meaning, Definition, Components and Application
Conferencia de Abertura_Virgilio Almeida.pdf
Deep Research and Analysis - by Ms. Oceana Wong
UGC NET Paper 1 Syllabus | 10 Units Complete Guide for NTA JRF
CXC-AD Associate Degree Handbook (Revised)
Time Series Analysis - Method of Simple Moving Average 3 Year and 4 Year Movi...
DEPED MEMORANDUM 089, 2025 PMES guidelines pptx
Agentic AI and AI Agents 20251121.pdf - by Ms. Oceana Wong
1. Doing Academic Research: Problems and Issues, 2. Academic Research Writing...
Anatomy of the eyeball An overviews.pptx
Masterclass on Cybercrime, Scams & Safety Hacks.pptx
Cattolica University - Lab Generative and Agentic AI - Mario Bencivinni
Finals - History and Geography Quiz - Around the World in 80 Questions - IITK
বাংলাদেশ অর্থনৈতিক সমীক্ষা - ২০২৫ with Bookmark.pdf
Time Series Analysis - Weighted (Unequal) Moving Average Method
In this document
Powered by AI

Introduction to Python modules, defining a module, contents (functions, classes, variables), and how to save code in a .py file.

Methods of loading modules using 'import' and 'from-import'. Examples include importing entire modules or specific functions.

Functions like dir() to list module content and reload() to refresh loaded modules.

Overview of Python packages, their structure, and an example of a library management system with sub-packages.

Modules in Python Programming

  • 1.
  • 2.
    MODULES A pythonmodules 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 MODULEIN PYTHON CODE Python provides 2 types of statements: Import Statement From-import Statement
  • 4.
    IMPORT STATEMENT Importstatement 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 regardlessof the number of times. Syntax:import module1, modeule2, . . . . , module n Example:import filename = input(“Enter your name:”)file.displayMsg(name)
  • 5.
    FROM-IMPORT STATEMENT Itprovides the flexibility to import only the specific attributes of a module. Syntax:from <module-name> import <name1>, <name2> . . . Calculation.pydef sum(a,b):return a + bdef mul(a,b):return a * bdef div(a,b):return a/b
  • 6.
    EXAMPLE Myprogram.pyfrom calculationimport sum #it will import only the sum() from calculation.pya = 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 thisname 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 jsonlist = 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 usthe reload( ) function. Syntax:reload(<module-name>) Example:reload(calculation)
  • 10.
    PYTHON PACKAGES Thepackages in python facilitate the developer with the application development environment byproviding 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. Thesub-packages contain the python modules.

[8]ページ先頭

©2009-2025 Movatter.jp