Python math.sin()方法 (Python math.sin() method)
math.sin() method is a library method of math module, it is used to get the sine of the number in radians, it accepts a number returns the cosine of the given number in radians.
math.sin()方法是数学模块的库方法,用于获取以弧度为单位的数字的正弦值,它接受一个以弧度为单位返回给定数字的余弦值的数字。
Note: math.sin() method accepts the only number, if we provide anything else except the number, it returns error TypeError - "TypeError: a float is required".
注意: math.sin()方法接受唯一的数字,如果我们提供除数字以外的其他任何内容,它将返回错误TypeError- “ TypeError:需要浮点数” 。
Syntax of math.sin() method:
math.sin()方法的语法:
math.sin(x)
Parameter(s): x – is the number whose sine to be calculated.
参数: x –是要计算其正弦的数字。
Return value: float – it returns a float value that is the sine value of the number x radians.
返回值: float-它返回一个浮点值,该值是数字x弧度的正弦值。
Example:
例:
Input:
a = 0.278
# function call
print(math.sin(a))
Output:
0.27443298625778634
Python代码演示math.sin()方法的示例 (Python code to demonstrate example of math.sin() method)
# python code to demonstrate example of
# math.sin() method
# importing math module
import math
# number
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))
Output
输出量
sin( -1 ) is = -0.8414709848078965
sin( 0 ) is = 0.0
sin( 0.278 ) is = 0.27443298625778634
sin( 1 ) is = 0.8414709848078965
TypeError example
TypeError示例
# python code to demonstrate example of
# math.sin() method with an exception
# importing math module
import math
# number
a = "2"
print("sin(",a,") is = ", math.sin(a))
Output
输出量
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
翻译自: https://www.includehelp.com/python/math-sin-method-with-example.aspx