[Tutor] Python root.
alan.gauld at btinternet.com
Mon Apr 19 00:19:02 CEST 2010
"Aidas" <aidas at vineva.lt> wrote
> You had written how to ger root in python. The way is:
> from math import sqrt
> print sqrt( 49 )".
> I noticed that if I write just "print sqrt(49)" I get nothing.
> So why I need to write "from math import sqrt"
Others have explained that you need to import the name sqrt from
the math module because sqrt is not defined as a "built-in" Python
function. But you can achieve the same thing using the pow() function,
which is built in - pow(49,0.5) - or the exponentiation operator - 49 ** 0.5
without using import...
You can read more about import and modules in the "Modules and
Functions" topic of my tutorial and more detail still in the "Whats in a name?"
Author of the Learn to Program web site
More information about the Tutor