Python中求数字的平方根和平方的几种方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Jerry_1126/article/details/82917405

方法一: 使用内置模块

>>> import math

>>> math.pow(12, 2)     # 求平方
144.0

>>> math.sqrt(144)      # 求平方根
12.0

>>>

方法二: 使用表达式

>>> 12 ** 2             # 求平方
144

>>> 144 ** 0.5          # 求平方根
12.0

>>> 

方法三: 使用内置函数

>>> pow(12, 2)          # 求平方
144

>>> pow(144, .5)        # 求平方根
12.0

>>>

猜你喜欢

转载自blog.csdn.net/Jerry_1126/article/details/82917405
今日推荐