Python中带有示例的math.sin()方法
Pythonmath.sin()方法
math.sin()方法是数学模块的一种库方法,用于获取以弧度为单位的数字的正弦,它接受一个以弧度为单位返回给定数字的余弦的数字。
注意:math.sin()方法接受的唯一的号码,如果我们提供任何其他除外数量,则返回错误类型错误-“类型错误:需要浮动”。
它的语法math.sin()方法:
math.sin(x)
Parameter(s):x–是要计算其正弦的数字。
返回值:float-返回一个浮点值,该值是数字x弧度的正弦值。
示例
Input: a = 0.278 #函数调用 print(math.sin(a)) Output: 0.27443298625778634
Python代码演示示例math.sin()方法
#python代码演示示例 # math.sin() method #导入数学模块 import math #数 a = -1 print("sin(",a,") is = ", math.sin(a)) a = 0 print("sin(",a,") is = ", math.sin(a)) a = 0.278 print("sin(",a,") is = ", math.sin(a)) a = 1 print("sin(",a,") is = ", math.sin(a))
输出结果
sin( -1 ) is = -0.8414709848078965 sin( 0 ) is = 0.0 sin( 0.278 ) is = 0.27443298625778634 sin( 1 ) is = 0.8414709848078965
TypeError示例
#python代码演示示例 # math.sin() method with an exception #导入数学模块 import math #数 a = "2" print("sin(",a,") is = ", math.sin(a))
输出结果
Traceback (most recent call last): File "/home/main.py", line 9, in <module> print("sin(",a,") is = ", math.sin(a)) TypeError: a float is required