Python中的角度转换功能

Python Angular转换函数/方法 (Python Angular conversion functions/methods)

In python programming language, there are some of the built-in functions which are defined in math module – they can be used for angular conversion i.e. to convert angle values, there are two angular conversion functions:

在python编程语言中 , 数学模块中定义了一些内置函数–它们可用于角度转换,转换角度值 ,有两个角度转换函数

  1. math.degrees()

    math.degrees()

    It is used to convert angle value from radians to degrees.

    用于将角度值从弧度转换为度。

  2. math.radians()

    math.radians()

    It is used to convert angle value from degrees to radians.

    用于将角度值从度转换为弧度。

Syntax of math.degrees() and math.radians() functions:

math.degrees()和math.radians()函数的语法:

    math.degrees(x)
    math.radians(x)

Example:

例:

    Input:
    x = 10.25 # value in radians

    # converting & printing in degrees
    x = math.degrees(x)
    print(x)

    # again, converting & printing in radians
    x = math.radians(x)
    print(x)

    Output:
    587.2817400090938
    10.25

Python代码演示角度转换函数的示例 (Python code to demonstrate example of angular conversion functions)

# Python code to demonstrate example of 
# math.degrees() and math.radians() methods

# importing math module
import math 

# angle x in radians
x = 10.25
print("x in radians: ", x)

# converting to degrees
x = math.degrees(x)
print("x in degrees: ", x)

# now again converting to radians
x = math.radians(x)
print("x in radians: ", x)

Output

输出量

x in radians:  10.25
x in degrees:  587.2817400090938
x in radians:  10.25

Note: If we provide anything except a number type value to these functions, they returns a TypeError.

注意:如果我们向这些函数提供数字类型值以外的任何东西,它们将返回TypeError

# Python code to demonstrate example of 
# math.degrees() with exception

# importing math module
import math 

# angle x in string (invalid)
x = "10.25"

# converting to degrees
x = math.degrees(x)
print("x in degrees: ", x)

Output

输出量

Traceback (most recent call last):
  File "/home/main.py", line 12, in 
    x = math.degrees(x)
TypeError: a float is required


翻译自: https://www.includehelp.com/python/angular-conversion-functions.aspx

你可能感兴趣的:(编程语言,python,java,深度学习,机器学习)