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 <module>
    x = math.degrees(x)
TypeError: a float is required


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

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值