Python3 acos()函式

2019-10-16 23:12:13
acos() 方法返回x的反餘弦(弧度)。

語法

以下是 acos() 方法的語法:
acos(x)
註:此功能直接是無法存取的,所以需要匯入 math 模組,然後需要用 math 靜態物件呼叫這個函式。

引數

  • x -- 這必須在範圍內的數位值-1到1。如果x大於1,然後將產生"math domain error"。

返回值

這個方法以弧度返回x的餘弦值。

範例

下面的例子顯示 acos() 方法的使用。
#!/usr/bin/python3
import math

print ("acos(0.64) : ",  math.acos(0.64))
print ("acos(0) : ",  math.acos(0))
print ("acos(-1) : ",  math.acos(-1))
print ("acos(1) : ",  math.acos(1))
當我們執行上面的程式,它會產生以下結果:
acos(0.64) :  0.876298061168
acos(0) :  1.57079632679
acos(-1) :  3.14159265359
acos(1) :  0.0