Python math.radians() 方法



Python math.radians() 方法用於將角度從度轉換為弧度。

在數學中,基數的冪是指基數自身相乘的結果,指數表示基數相乘的次數。

語法

以下是Python math.radians()方法的語法:

math.radians(x)

注意 - 此函式不能直接訪問,因此我們需要匯入math 模組,然後我們需要使用 math 靜態物件呼叫此函式。

引數

  • x - 必須是數值。

返回值

此方法返回角度的弧度值。

示例 1

如果我們將正值作為引數傳遞給此方法,則它將返回正值。如果傳遞的引數為負數,則返回負值。

以下示例演示了 Python math.radians() 方法的用法。

import math
print ("radians(3) : ",  math.radians(3))
print ("radians(-3) : ",  math.radians(-3))
print ("radians(math.pi) : ",  math.radians(math.pi))
print ("radians(-(math.pi/2)) : ",  math.radians(-(math.pi/2)))
print ("radians(math.pi/4) : ",  math.radians(math.pi/4))

執行以上程式後,輸出結果如下:

radians(3) :  0.0523598775598
radians(-3) :  -0.0523598775598
radians(math.pi) :  0.0548311355616
radians(-(math.pi/2)) :  -0.027415567780803774
radians(math.pi/4) :  0.0137077838904

示例 2

如果我們將 NaN 值或 0 作為引數傳遞給此方法,則它將返回 0。

import math
num = 0
res = math.radians(num)
print ("The radian of 0 is: ", res)

執行以上程式碼後,輸出結果如下:

The radian of 0 is:  0.0

示例 3

在以下示例中,我們將浮點值作為引數傳遞給radians() 方法

import math
num = 78.56
res = math.radians(num)
print ("The radians of a float value is: ", res)

以上程式碼的輸出如下:

The radians of a float value is:  1.3711306603667452

示例 4

在下面給出的示例中,我們建立了一個元組和一個列表。然後使用 radians() 方法檢索指定索引處元組和列表元素的弧度。

import math
List = [874.44, 36.54, 38.84, 92.35, 9.9]
Tuple = (34, 576, 93, 85, 62)
print ("The radians of the first List item is: ", math.radians(List[0]))
print ("The radians of the fifth List item is: ", math.radians(List[4]))
print ("The radians of the second tuple item is: ", math.radians(Tuple[1]))

以上程式碼的輸出如下:

The radians of the first List item is:  15.261857111139216
The radians of the fifth List item is:  0.17278759594743864
The radians of the second tuple item is:  10.053096491487338
python_maths.htm
廣告