可以使用 math 模块中的 sqrt 函数来计算开根号。

示例代码:

import math

# 计算2的平方根
result = math.sqrt(2)
print(result)  # 输出1.4142135623730951

# 计算3的平方根
result = math.sqrt(3)
print(result)  # 输出1.7320508075688772

也可以使用指数运算符 ** 来计算开方,例如:

# 计算2的平方根
result = 2 ** 0.5
print(result)  # 输出1.4142135623730951

# 计算3的平方根
result = 3 ** 0.5
print(result)  # 输出1.7320508075688772
Python 开根号:两种方法详解

原文地址: http://www.cveoy.top/t/topic/mJF2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录