X root Operator help

Steve Holden steve at holdenweb.com
Wed Apr 18 12:30:48 EDT 2007


Michael Hoffman wrote:
> lucidparadox wrote:
>> I'm currently new to Python and I haven't been able to find the
>> operator/math function to find the square root or even the x root of a
>> number.
> 
> For square root, use math.sqrt(y)
> 
> For x root use y**(1/x)
> 
[...]

  >>> 1/3
0
  >>> 3.14159 ** (1/3)
1.0
  >>>

So the cube root of pi is 1? I don't think so.

For generic roots use y ** (1.0 / x)

until future versions of Python produce floating point results from all 
divisions as necessary.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list