Python Glossary Русский

all Python 3mathterm

math.sin

trigonometry

Returns the sine of an angle given in radians. To convert degrees to radians use math.radians().

Syntax

math.sin(x)

math.pi is only a float approximation of π, so exact zeros never show up: math.sin(math.pi) returns 1.22e-16, not 0. Never test the result against 0 or 1 with ==; use math.isclose() or round() to a fixed number of digits. The inverse, math.asin(), also speaks radians, so pass its result through math.degrees() when you need degrees.

Examples

import math
print(math.sin(0))            # → 0.0
print(math.sin(math.pi/2))    # → 1.0
print(math.sin(math.pi))      # → ?  (значение зависит от системной libm — карточка учит наличию погрешности, а не её цифрам)
print(round(math.sin(math.pi/6), 2))  # → 0.5
print(math.sin(math.pi/4))    # → 0.7071...
print(math.sin(-math.pi/2))   # → -1.0

See also

Open in the full glossarydocs.python.orgReport an inaccuracy