Simply in python module is just a python file having .py extension . A module can
define classes , functions and varibales .Module just allow you to logically arrange your code . Which makes you easy to undersatnd . Kindly find the below exaple for the same
def simple_func(par):
print “hello”, par
return
In python Modules are imported from other modules using the ‘import’ command . You can use any python source file as a module by executing an import statement in some other python source file .
Syntax for importcommand :
import module1, module2.....
This line means we are importing two modules into this . This will check if module is available in search path . Basically serach path contain list of directories that the interpreter searches before importing a module . For example
>>> import math
>>> a=10
>>> math.sqrt(a)
3.1622776601683795
we can see the all functions of any module and datatype simply using dir command , find the example as given below
import math
>>> dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
Softcrayons tech solution is a IT cum industrial institute in Ghaziabad. it offers best python training.
define classes , functions and varibales .Module just allow you to logically arrange your code . Which makes you easy to undersatnd . Kindly find the below exaple for the same
def simple_func(par):
print “hello”, par
return
In python Modules are imported from other modules using the ‘import’ command . You can use any python source file as a module by executing an import statement in some other python source file .
Syntax for importcommand :
import module1, module2.....
This line means we are importing two modules into this . This will check if module is available in search path . Basically serach path contain list of directories that the interpreter searches before importing a module . For example
>>> import math
>>> a=10
>>> math.sqrt(a)
3.1622776601683795
we can see the all functions of any module and datatype simply using dir command , find the example as given below
import math
>>> dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
Softcrayons tech solution is a IT cum industrial institute in Ghaziabad. it offers best python training.
No comments:
Post a Comment