Function Imports


my code was:

from module import math.sqrt()

it is not running. Pls help!!


Youre trying to use one function from math module?
then do this..

from module_name import function_name


ok thankyou very much


Is it clear to you ? or if not we can discuss?.


Would you please explain me?


Think module as a collection of functions and already defined things.
Like Python have tons of modules to deal with different problems, for maths we have math module for time we have datetime module etc.
But to use a module we need to import them in our program.

Note: Import is a keyword in python whose main work is to find the module,initialize it and make different elements of module available for program

say there is a module named X and it has functions T , U, V
so if we want to use this module, we write this..

import moduleName


import X

Now if we want to use the function..then we will use dot operator with functions name..

module_name.function_name(parameters here)



Like take an example of a real module math..

but sometimes we only need one function from a module..
then we use this syntax..

from module_name import function_name


from X import T

Now we don't need dot notation on module name..
we can simply use our module function..


a real example of math module..


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.