Home » Python

math.sin() method with example in Python

Python math.sin() method: Here, we are going to learn about the math.sin() method with example in Python.
Submitted by IncludeHelp, on April 21, 2019

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.

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

Syntax of math.sin() method:

    math.sin(x)

Parameter(s): x – is the number whose sine to be calculated.

Return value: float – it returns a float value that is the sine value of the number x radians.

Example:

    Input:
    a = 0.278

    # function call
    print(math.sin(a))

    Output:
    0.27443298625778634

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

# 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


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.