AppDividend
Latest Code Tutorials

# Python sin() Function | Math.sin() in Python Example

Python sin() is an inbuilt method that is defined under the math module, which is used to find the sine value of the parameter passed in radians. For example, if x is passed as a parameter in sin function (sin(x)), it 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 use to call the sin() function using a static object.

## Python sin()

Content Overview

In Python, the math module contains several mathematical operations, which can be performed with ease using the module. The math.sin() function returns a sine of the value passed as an argument. The value passed in the sin() function should be 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 is 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 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 which is 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 which represents the ratio between hypotenuse and opposite.