Python sin() is a built-in math function used to find the sine value of the parameter passed in radians. It accepts x as a parameter and returns the sine value of x in radians.
Syntax
math.sin(var)
Here var is the variable of which sine we have to find.
Parameters
It takes one parameter var, which takes values of the numeric datatype and throws TypeError if an argument of any other data type is passed.
Return Value
It returns the sine value of the number in the float datatype.
Example 1: Write a program to show the working of the sin() method in Python.
import math
a1 = 0.36
b1 = 1
c1 = -1
d1 = -0.36
print("Value for parameter ", a1, " is ", math.sin(a1))
print("Value for parameter ", b1, " is ", math.sin(b1))
print("Value for parameter ", c1, " is ", math.sin(c1))
print("Value for parameter ", d1, " is ", math.sin(d1))
Output
Value for parameter 0.36 is 0.35227423327508994
Value for parameter 1 is 0.8414709848078965
Value for parameter -1 is -0.8414709848078965
Value for parameter -0.36 is -0.35227423327508994
In this example, we have seen that by passing a valid parameter different for different examples; we get the desired sin() method solution, which is the sine value of the parameter.
Example 2: Pass the value out of range from the sin() function
import math
a = 'Hello'
print(math.cos(a))
Output
TypeError: must be real number, not str
In this example, we’ve seen that passing a parameter, which is not a real number, throws a TypeError.
That’s it.