To Play with Modules in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

To Play with Modules in Python

1. To import multiple modules we can use import math, random, sys 2. To import only some useful functions of a module, we can use the code as from math import sqrt 3. We can also give some alias name to the particular function after import statement from math import sqrt as square_root 4. We can also give alias names for different functions with in a module using commas. from math import sqrt as square_root, cos as cosine, tan as tangent print square_root(49) >>>7.0 print cosine(0) >>>1 print tan(45) >>>1 5. We can print the list of all functions within a module using the line of code import math print 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'] 6. We can also get the full documentation of all functions using a line of code import math print help(math.log) >>>Help on built-in function log in module math: log(...) log(x[, base]) Return the logarithm of x to the given base. If the base not specified, returns the natural logarithm (base e) of x.

12th Dec 2016, 1:26 PM
Madhu Muppala
Madhu Muppala - avatar
4 Answers
+ 5
this is not a question!
14th Dec 2016, 5:09 AM
Ahri Fox
Ahri Fox - avatar
+ 2
This isnt a Question but helpful ty
4th Jan 2017, 6:04 PM
z77
+ 1
It seems you are posting your own tutorials and guides in Q&A....
14th Dec 2016, 6:23 AM
Towfique Kabir
Towfique Kabir - avatar
+ 1
This is not a question but you can comment in the modules in python.
26th Apr 2020, 4:20 PM
Kishore Kumar BP
Kishore Kumar BP - avatar