AppDividend
Latest Code Tutorials

# Python sin: How to Use Math.sin() Function

In Python, the math module contains several mathematical operations, which can be easily performed using the module. The math.sin() function returns a sine of the value passed as an argument. The value given in the sin() function should be in radians.

## Python sin()

Python sin() is a built-in math function that is used to find the sine value of the parameter passed in radians. The sin() function accepts x as a parameter and returns the sine value of x in radians.

We can use a math module by importing it. The syntax would be import math; after importing, we call the sin() function using a static object.

### 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.

See the following example.

```import math

var = 0.36
print(math.sin(var))
```

### Example programs on sin() method in Python

#### 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: Write a program to pass the value out of range from the sin() function and display the output.

See the following example.

```import math

a = 'Hello'
print(math.cos(a))
```

#### Output

```For 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.

## Conclusion

Python sin() function is used to find the sine of a given argument in radians, where sine is a trigonometric function that represents the ratio between hypotenuse and opposite.