>>> import math
>>> math.sqrt(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
看到原因了吧,给一个负数开平方!
在Python中尝试对负数开平方根会引发`ValueError: math domain error`。这个错误表明在数学运算中遇到了无效的操作,即负数无法在实数域内取平方根。
>>> import math
>>> math.sqrt(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
看到原因了吧,给一个负数开平方!

被折叠的 条评论
为什么被折叠?
