On Sun, Apr 18, 2010 at 10:21 AM, Aidas <ai...@vineva.lt> wrote:

> Hello.
> In here http://mail.python.org/pipermail/tutor/2001-February/003385.htmlYou 
> had written how to ger root in python. The way is: "from math import
> sqrtprint 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" instead of write just "print sqrt( 49
> )"?
>
> P.S. Sorry about english-I'm lithuanian. :)
>
>
>>> sqrt()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'sqrt' is not defined

That traceback tells you what the error is and where the error is. The
NameError is the specific type of error, and it tells you why - sqrt is not
defined.

In order to call a function its name needs to be defined. When you type '>>>
from math import sqrt' then you are importing the function (or name) sqrt
from the math module.

Then you can use it:
>>> from math import sqrt
>>> print sqrt(49)
7.0


HTH,
Wayne



> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to