Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python modules

A programmer usually prefer the predefined functions and variables for document,
Modules are collection of several diffrent definitions(functions and variables)
and statements.Or to put simply The files with ".py" appended at the name of the
source code,the user can import that module(files) or specific function fromthat
module into the file.
programmer use the module,complete project in less time and more efficient way.
programmer generally import either the module which user saved with ".py" or can
use some standard module like random,queue,array,math,profile,statistics etc....
just type "help('modules')" and you can see all standard modules in interactive
mode.
-------------------------------------------------------------------------------
 Eg--> # here entire math universe will come into the program 
>>> import math
>>> math.cos(60)# math.cos()
-0.9524129804151563
>>> math.ceil(6.12)#math.ceil()
7
>>> math.log2(4)#math.log2()
2.0
-------------------------------------------------------------------------------
#but if you want specific built in function then use "from".
 Eg--> # only perticular function will come from the math module.
>>> from math import sqrt,sin
>>> sqrt(9)#math module will be undefine since only function sqrt,sin defined
3.0
>>> sin(60)# sin is imported from math and "math." is not required
-0.3048106211022167
>>> cos(60)# cos is not part of the built in function that imported from math.
'''Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    cos(60)
NameError: name 'cos' is not defined'''
>>> math.cos(60)# this gives error because math has not been imported
'''Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    math.cos(60)
NameError: name 'math' is not defined'''
-------------------------------------------------------------------------------
 
PREVIOUS NEXT
Tagged: #python #modules
ADD COMMENT
Topic
Name
7+1 =