Textbook Solutions refer https://pythonxiisolutions.blogspot.com/
Practical's Solutions refer https://prippython12.blogspot.com/
A library is a collection of the modules that caters together to specific type of needs. Smaller handleable units are modules. Standard library modules. Modularity reduced complexity to some extend. A package is a directory that contains sub packages and modules in it along with
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
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>