下面是這種情況:歧義基本的算術運算的Python
In [5]: (2.0 - 5.0**(0.5)) ** (1.0/3.0)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-d064023f1ac5> in <module>()
----> 1 (2.0 - 5.0**(0.5)) ** (1.0/3.0)
ValueError: negative number cannot be raised to a fractional power
In [7]: -1.0 ** (1.0/3.0)
Out[7]: -1.0
上述操作正在對Python解釋器來完成。對於第一個表達式,它給出了值錯誤,並說negative number can't have fractional power
!所以,首先,爲什麼這個錯誤很明顯,-ve數字可以有立方根或第五根等。另外,如果是這種情況,它應該是一致的,而在第二種情況下,當-1被提升爲分數功率(1/3)。
有人可以解釋爲什麼是這種情況?
你使用的是Python 2不是嗎?)在py3k中,實際工作得到(0.30901699437494756 + 0。535233134659635j) –
yes,它的python2 – vish4071
然後只是複雜的((2.0 - 5.0 **(0.5)))**(1.0/3.0) –