SlideShare a Scribd company logo
1 of 8
Using Python Library
Python Functions
Library
A Library refers to a collection of modules that
together cater to specific type of needs or
applications. A library can have multiple modules
Standard Library
Math random Urllib Cmath
Commonly used libraries in Python are :
1) Standard Library- default distributed with python to
provide various functionalities.
(modules- math,random,cmath,Urllib,statistics)
1) NumPy – provide tool to manipulate numeric arrays.
2) SciPy- provide logarithmic and mathematical tools
for scientific calculations.
3) Tkinter-offers user interface toolkit to create user
friendly GUI.
4) Matplotlib-offers functions to produce plots, graphs,
charts etc.
Module/Function
The act of partitioning a program into individual components (known as modules) is called modularity. A module is a
separate unit itself. A python module is a normal python file (.py)
>>>import math
>>>help (math)
Help on built-in module math:
NAME
math
DESCRIPTION
This module is always available. It provides access to the
mathematical functions defined by the C standard.
FUNCTIONS
:
:
:
sin(x)
Returns the sine of value
passed as argument
cos(x)
Returns the co-sine of value passed as
argument
1. DATA
2. e = 2.718281828459045
3. inf = inf
4. nan = nan
5. pi = 3.141592653589793
6. tau = 6.283185307179586
Structure of Python Module
Lengths conversions.py
docstrings triple quoted
comments
variables labels for data
& constants
classes templates to create
objects
objects instances of classes.
statements instructions
functions named group of instructions
” ” ” conversion functions mile -> km, feet -> inch ” ” ”
Unitkm=‘Km’
Unitfeet=‘Inches’
Unitmile=‘mile’
def mile_to_km(x):
#1 mile=1.609344km
return x * 1.609344
def feet_to_inch(x):
#1 feet=12 inches
return x* 12
To create this kind of structure we will have to create
3 folders as per levels given above(Conversion->Length and Mass)
Length folder will have a file(module) LengthConversion.py, and it will have multiple functions
Mass folder will have a file(module) MassConversion.py, and it will have multiple conversion
functions.
Conversion folder will have a file(module) Details.py, and it will have a function description() in it.
Each folder should have a empty file named __init__.py
Now Move/Copy this Conversion folder to C:UsersAdminAnaconda3Libsite-packages
Lets create a structure
Conversion
Length
LengthConversion.py
Mass
MassConversion.py
Now testing time
run following sequence of commands
Import vs from import command
●import <module>
●All defined functions and variables created in
module are now available to the program
●A new namespace is setup with the same name as
of module
●from <module> import <object>
●Only asked functions and variables from the module are
made available to the program.
●No new namespace is created, imported functions and
variables are just added to current namespace.
If your program already has a variable with the same
name as the one imported via module, then the variable in
your program will hide imported variable with same
name.
avoid using command from <module> import *
instead use import <module>

More Related Content

What's hot

Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaEdureka!
 
Dynamic Memory Allocation
Dynamic Memory AllocationDynamic Memory Allocation
Dynamic Memory Allocationvaani pathak
 
4 dynamic memory allocation
4 dynamic memory allocation4 dynamic memory allocation
4 dynamic memory allocationFrijo Francis
 
1 sample16c132 java-programming
1 sample16c132 java-programming1 sample16c132 java-programming
1 sample16c132 java-programmingMary Jones
 
Devry gsp 215 week 6 i lab virtual memory new
Devry gsp 215 week 6 i lab virtual memory newDevry gsp 215 week 6 i lab virtual memory new
Devry gsp 215 week 6 i lab virtual memory newwilliamethan912
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)Janki Shah
 
Distributed Tracing, from internal SAAS insights
Distributed Tracing, from internal SAAS insightsDistributed Tracing, from internal SAAS insights
Distributed Tracing, from internal SAAS insightsHuy Do
 
Dynamic memory Allocation in c language
Dynamic memory Allocation in c languageDynamic memory Allocation in c language
Dynamic memory Allocation in c languagekiran Patel
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4Bianca Teşilă
 
Spike sorting-tutorial
Spike sorting-tutorialSpike sorting-tutorial
Spike sorting-tutorialvacagodx
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPyDevashish Kumar
 
TLPI - 7 Memory Allocation
TLPI - 7 Memory AllocationTLPI - 7 Memory Allocation
TLPI - 7 Memory AllocationShu-Yu Fu
 

What's hot (20)

Introduction to numpy
Introduction to numpyIntroduction to numpy
Introduction to numpy
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
 
Dynamic Memory Allocation
Dynamic Memory AllocationDynamic Memory Allocation
Dynamic Memory Allocation
 
NumPy
NumPyNumPy
NumPy
 
Performance
PerformancePerformance
Performance
 
4 dynamic memory allocation
4 dynamic memory allocation4 dynamic memory allocation
4 dynamic memory allocation
 
1 sample16c132 java-programming
1 sample16c132 java-programming1 sample16c132 java-programming
1 sample16c132 java-programming
 
Devry gsp 215 week 6 i lab virtual memory new
Devry gsp 215 week 6 i lab virtual memory newDevry gsp 215 week 6 i lab virtual memory new
Devry gsp 215 week 6 i lab virtual memory new
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Automation using Puppet 3
Automation using Puppet 3 Automation using Puppet 3
Automation using Puppet 3
 
Distributed Tracing, from internal SAAS insights
Distributed Tracing, from internal SAAS insightsDistributed Tracing, from internal SAAS insights
Distributed Tracing, from internal SAAS insights
 
Dynamic memory Allocation in c language
Dynamic memory Allocation in c languageDynamic memory Allocation in c language
Dynamic memory Allocation in c language
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4
 
Spike sorting-tutorial
Spike sorting-tutorialSpike sorting-tutorial
Spike sorting-tutorial
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
 
Scientific Python
Scientific PythonScientific Python
Scientific Python
 
C dynamic ppt
C dynamic pptC dynamic ppt
C dynamic ppt
 
Stack Data structure
Stack Data structureStack Data structure
Stack Data structure
 
TLPI - 7 Memory Allocation
TLPI - 7 Memory AllocationTLPI - 7 Memory Allocation
TLPI - 7 Memory Allocation
 

Similar to Python library

Python Libraries and Modules
Python Libraries and ModulesPython Libraries and Modules
Python Libraries and ModulesRaginiJain21
 
pythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docxpythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docxRameshMishra84
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdfSoumyadityaDey
 
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptxPython-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptxanushya2915
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2sadhana312471
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdfDaddy84
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2Giovanni Della Lunga
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsRuth Marvin
 
fileop report
fileop reportfileop report
fileop reportJason Lu
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Ganesan Narayanasamy
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84Mahmoud Samir Fayed
 
FLESCH INDEX AND SYS AND OS MODULE IN PYTHON PROGRAMMING LANGUAGE
FLESCH INDEX AND SYS AND OS MODULE IN PYTHON PROGRAMMING LANGUAGEFLESCH INDEX AND SYS AND OS MODULE IN PYTHON PROGRAMMING LANGUAGE
FLESCH INDEX AND SYS AND OS MODULE IN PYTHON PROGRAMMING LANGUAGEJustin George
 
Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Fwdays
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptxkrushnaraj1
 

Similar to Python library (20)

ch 2. Python module
ch 2. Python module ch 2. Python module
ch 2. Python module
 
PyCon Estonia 2019
PyCon Estonia 2019PyCon Estonia 2019
PyCon Estonia 2019
 
Python Libraries and Modules
Python Libraries and ModulesPython Libraries and Modules
Python Libraries and Modules
 
pythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docxpythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docx
 
Python for lab_folk
Python for lab_folkPython for lab_folk
Python for lab_folk
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
 
Python libraries
Python librariesPython libraries
Python libraries
 
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptxPython-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
 
fileop report
fileop reportfileop report
fileop report
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84
 
FLESCH INDEX AND SYS AND OS MODULE IN PYTHON PROGRAMMING LANGUAGE
FLESCH INDEX AND SYS AND OS MODULE IN PYTHON PROGRAMMING LANGUAGEFLESCH INDEX AND SYS AND OS MODULE IN PYTHON PROGRAMMING LANGUAGE
FLESCH INDEX AND SYS AND OS MODULE IN PYTHON PROGRAMMING LANGUAGE
 
Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
 

More from ToniyaP1

Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear listsToniyaP1
 
Python algorithm efficency
Python algorithm efficencyPython algorithm efficency
Python algorithm efficencyToniyaP1
 
Python data file handling
Python data file handlingPython data file handling
Python data file handlingToniyaP1
 
Python functions
Python functionsPython functions
Python functionsToniyaP1
 
Python recursion
Python recursionPython recursion
Python recursionToniyaP1
 

More from ToniyaP1 (6)

Numpy
NumpyNumpy
Numpy
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
 
Python algorithm efficency
Python algorithm efficencyPython algorithm efficency
Python algorithm efficency
 
Python data file handling
Python data file handlingPython data file handling
Python data file handling
 
Python functions
Python functionsPython functions
Python functions
 
Python recursion
Python recursionPython recursion
Python recursion
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

Python library

  • 2. Library A Library refers to a collection of modules that together cater to specific type of needs or applications. A library can have multiple modules Standard Library Math random Urllib Cmath
  • 3. Commonly used libraries in Python are : 1) Standard Library- default distributed with python to provide various functionalities. (modules- math,random,cmath,Urllib,statistics) 1) NumPy – provide tool to manipulate numeric arrays. 2) SciPy- provide logarithmic and mathematical tools for scientific calculations. 3) Tkinter-offers user interface toolkit to create user friendly GUI. 4) Matplotlib-offers functions to produce plots, graphs, charts etc.
  • 4. Module/Function The act of partitioning a program into individual components (known as modules) is called modularity. A module is a separate unit itself. A python module is a normal python file (.py) >>>import math >>>help (math) Help on built-in module math: NAME math DESCRIPTION This module is always available. It provides access to the mathematical functions defined by the C standard. FUNCTIONS : : : sin(x) Returns the sine of value passed as argument cos(x) Returns the co-sine of value passed as argument 1. DATA 2. e = 2.718281828459045 3. inf = inf 4. nan = nan 5. pi = 3.141592653589793 6. tau = 6.283185307179586
  • 5. Structure of Python Module Lengths conversions.py docstrings triple quoted comments variables labels for data & constants classes templates to create objects objects instances of classes. statements instructions functions named group of instructions ” ” ” conversion functions mile -> km, feet -> inch ” ” ” Unitkm=‘Km’ Unitfeet=‘Inches’ Unitmile=‘mile’ def mile_to_km(x): #1 mile=1.609344km return x * 1.609344 def feet_to_inch(x): #1 feet=12 inches return x* 12
  • 6. To create this kind of structure we will have to create 3 folders as per levels given above(Conversion->Length and Mass) Length folder will have a file(module) LengthConversion.py, and it will have multiple functions Mass folder will have a file(module) MassConversion.py, and it will have multiple conversion functions. Conversion folder will have a file(module) Details.py, and it will have a function description() in it. Each folder should have a empty file named __init__.py Now Move/Copy this Conversion folder to C:UsersAdminAnaconda3Libsite-packages Lets create a structure Conversion Length LengthConversion.py Mass MassConversion.py
  • 7. Now testing time run following sequence of commands
  • 8. Import vs from import command ●import <module> ●All defined functions and variables created in module are now available to the program ●A new namespace is setup with the same name as of module ●from <module> import <object> ●Only asked functions and variables from the module are made available to the program. ●No new namespace is created, imported functions and variables are just added to current namespace. If your program already has a variable with the same name as the one imported via module, then the variable in your program will hide imported variable with same name. avoid using command from <module> import * instead use import <module>