Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python sin() function

Python sin() function

Python Numbers Python Numbers


Description

sin() Returns the sine of x radians.


Syntax

The syntax of the sin() method is as follows:


import math

math.sin(x)

**Note:** sin() cannot be accessed directly; you need to import the math module and call the method through the static math object.


Parameters


Return Value

Returns the sine of x radians, a value between -1 and 1.


Example

The following shows examples of using the sin() method:

Example

#!/usr/bin/python

import

math

print

"sin(3) : "

,

 

math

.

sin

(

3

)

print

"sin(-3) : "

,

 

math

.

sin

(

3

)

print

"sin(0) : "

,

 

math

.

sin

(

0

)

print

"sin(math.pi) : "

,

 

math

.

sin

(

math

.

pi

)

print

"sin(math.pi/2) : "

,

 

math

.

sin

(

math

.

pi

/

2

)

Running the example above produces:


sin(3) :  0.14112000806
sin(-3) :  -0.14112000806
sin(0) :  0.0
sin(math.pi) :  1.22460635382e-16
sin(math.pi/2) :  1

Python Numbers Python Numbers