Python| sympy.sqrt() 方法
借助sympy.sqrt()方法,我们可以根据值以及符号简化的数学表达式来找到任何值的平方根。
Syntax: sqrt(val)
Parameters:
val – It is the value on which square root operation is to be performed.
Returns: Returns square root in terms of values and symbolically simplified mathematical expression corresponding to the input expression.
示例 #1:
# import sympy
from sympy import *
val = 256
print("Value : {}".format(val))
# Use sympy.sqrt() method
sqrt_val = sqrt(val)
print("Square root of value : {}".format(sqrt_val))
输出:
Value : 256
Square root of value : 16
示例 #2:
# import sympy
from sympy import *
val = 8
print("Value : {}".format(val))
# Use sympy.sqrt() method
sqrt_val = sqrt(val)
print("Square root of value : {}".format(sqrt_val))
输出:
Value : 8
Square root of value : 2*sqrt(2)