Python数字atan2()方法

Python数字atan2()方法返回atan(y / x)的反正切值,以弧度表示。

语法

以下是atan2()方法的语法 -

atan2(y, x)

注意 - 此函数不能直接访问,需要导入math模块,需要使用math静态对象调用此函数。

参数

  • y - 此参数必须是数字值。
  • x - 此参数必须是数字值。

返回值

  • 此方法返回atan(y / x),以弧度表示。

示例

以下示例显示了atan2()方法的用法。

#!/usr/bin/python3
import math

print ("atan2(-0.50,-0.50) : ",  math.atan2(-0.50,-0.50))
print ("atan2(0.50,0.50) : ",  math.atan2(0.50,0.50))
print ("atan2(5,5) : ",  math.atan2(5,5))
print ("atan2(-10,10) : ",  math.atan2(-10,10))
print ("atan2(10,20) : ",  math.atan2(10,20))

当运行上述程序时,它会产生以下结果 -

atan2(-0.50,-0.50) :  -2.35619449019
atan2(0.50,0.50) :  0.785398163397
atan2(5,5) :  0.785398163397
atan2(-10,10) :  -0.785398163397
atan2(10,20) :  0.463647609001

上一篇: Python数字 下一篇: Python字符串