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
A Presentation of PMES 2025-2028 with Salient features.pptx
PDF
1. Doing Academic Research: Problems and Issues, 2. Academic Research Writing...
PPTX
Plant Breeding: Its History and Contribution
PDF
*Unit-II A (Elements of Communication & Communication Style Matrix)
PPTX
Prelims - History and Geography Quiz - Around the World in 80 Questions - IITK
PDF
Deep Research and Analysis - by Ms. Oceana Wong
PPTX
Finals - History and Geography Quiz - Around the World in 80 Questions - IITK
PDF
UGC NET Paper 1 Syllabus | 10 Units Complete Guide for NTA JRF
PDF
ASRB NET 2025 Paper GENETICS AND PLANT BREEDING ARS, SMS & STODiscussion | Co...
PPTX
The hidden treasures Grade 5 Story with Motive Questions.pptx
PDF
AI Workflows and Workflow Rhetoric - by Ms. Oceana Wong
PDF
Digital Electronics – Registers and Their Applications
PPTX
Time Series Analysis - Weighted (Unequal) Moving Average Method
PPTX
Time Series Analysis - Least Square Method Fitting a Linear Trend Equation
PPTX
ATTENTION - PART 1.pptx cognitive processes -For B.Sc I Sem By Mrs.Shilpa Hot...
PDF
“Step-by-Step Fabrication of Bipolar Junction Transistors (BJTs)”
PPTX
General Wellness & Restorative Tonic: Draksharishta
PPTX
LYMPHATIC SYSTEM.pptx it includes lymph, lymph nodes, bone marrow, spleen
PDF
Past Memories and a New World: Photographs of Stoke Newington from the 70s, 8...
Risk Management and Regulatory Compliance - by Ms. Oceana Wong
A Presentation of PMES 2025-2028 with Salient features.pptx
1. Doing Academic Research: Problems and Issues, 2. Academic Research Writing...
Plant Breeding: Its History and Contribution
*Unit-II A (Elements of Communication & Communication Style Matrix)
Prelims - History and Geography Quiz - Around the World in 80 Questions - IITK
Deep Research and Analysis - by Ms. Oceana Wong
Finals - History and Geography Quiz - Around the World in 80 Questions - IITK
UGC NET Paper 1 Syllabus | 10 Units Complete Guide for NTA JRF
ASRB NET 2025 Paper GENETICS AND PLANT BREEDING ARS, SMS & STODiscussion | Co...
The hidden treasures Grade 5 Story with Motive Questions.pptx
AI Workflows and Workflow Rhetoric - by Ms. Oceana Wong
Digital Electronics – Registers and Their Applications
Time Series Analysis - Weighted (Unequal) Moving Average Method
Time Series Analysis - Least Square Method Fitting a Linear Trend Equation
ATTENTION - PART 1.pptx cognitive processes -For B.Sc I Sem By Mrs.Shilpa Hot...
“Step-by-Step Fabrication of Bipolar Junction Transistors (BJTs)”
General Wellness & Restorative Tonic: Draksharishta
LYMPHATIC SYSTEM.pptx it includes lymph, lymph nodes, bone marrow, spleen
Past Memories and a New World: Photographs of Stoke Newington from the 70s, 8...
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