XII-CS-UNIT-I-Part4-PYTHON-LIBRARIES-2020-21
XII-CS-UNIT-I-Part4-PYTHON-LIBRARIES-2020-21
XII-CS-UNIT-I-Part4-PYTHON-LIBRARIES-2020-21
CLASS-XII
DISTRIBUTION OF MARKS:
UNIT UNIT NAME MARKS
II Computer Networks 10
TOTAL 70
1. Module
2. Package
3. Library
Module is a file containing Python definitions, functions, variables,
classes and statements
Module:
-It is a file which contains python functions/global
variables/clases etc. It is just .py file which has python executable
code / statement.
<module_name>.<function_name>
Example: print(math.sqrt(25))
import math
print (math.sqrt(25))
print (math.log10(100))
OR
from math import *
print(sqrt(25))
print(log10(100))
OR
from math import *
print(sqrt(25)) #It will work
def area_rect(length,breadth):
return length*breadth
def area_sqr(side):
return side*side
def area_circle(rad):
return math.pi*rad*rad
For example, if the imported module is area, now you want to call
the function area_circle(), it would be called as area.area_circle()
For example:
from math import sqrt
print(sqrt(25))
Defining package
Step 1: Create a new folder which you want to act as package. The
name of folder will be the name of your package (“mypackage”)
Step 2: Create modules (.py) and save it in mypackage folder
(area.py and numcheck.py mypackahge)
#area.py
import math # my module
mynum=100
def area_rect(length,breadth):
return length*breadth
def area_sqr(side):
return side*side
def area_circle(rad):
return math.pi*rad*rad
# numcheck.py
import math
def even(num):
if num%2==0:
return 1
else:
return 0
def isprime(num):
for i in range (2,int(math.sqrt(num)+1)):
if num%i==0:
return 0
return 1
def palindrome(num):
mynum=num
n=0
while num!=0:
r=num%10
n=n*10+r
num = num//10
if mynum ==n:
return 1
else:
return 0
import mypackage.numcheck
n=int(input("Enter number"))
if(mypackage.numcheck.isprime(n)):
print("Number is prime")
else:
print("Number is composite")
OR
Library
It is a collection of various packages. Conceptually, there is no
difference between package and python library. In Python, a library
is used loosely to describe a collection of the core modules.
‘Standard library ‘of Python language comes bundled with the core
Python distribution are collection of exact syntax, token and
semantics of the Python language. The python standard library lists
down approx more than 200 such core modules that form the core
of Python.