Python math.sin() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math module

Definition

math.sin(x) computes the trigonometric sine of angle x, where x is measured in radians, not degrees.

If your angles are in degrees, wrap them with math.radians() before calling math.sin(), such as math.sin(math.radians(30)).

math.sin() is a function in Python's standard math module: import it with import math and call math.sin(...), or import the name directly with from math import sin.

Syntax

Import math and pass an angle in radians.

python
import math

y = math.sin(angle_radians)
CallWhat it does
math.sin(0)Returns 0.0.
math.sin(math.pi / 6)Returns 0.49999999999999994 (close to 0.5).
math.sin(math.pi)Returns 1.2246467991473532e-16 (near 0 due to float pi).
math.sin(float("inf"))Raises ValueError: domain error.

Because math.pi is a finite float approximation of pi, math.sin(math.pi) returns a tiny value near 1.22e-16 instead of exact 0.0.

Function signatures
python
math.sin(x, /)
# returns: float sine of x radians

Parameters

ParameterDescription
xRequired positional finite angle in radians (int or float).

Return Value

Return ValueDescription
floatSine of x in the range [-1.0, 1.0]; returns nan for nan.

Python Examples

Example 1 — Sample Sine Wave Displacement Across Angles

Convert degree angles to radians and print formatted wave amplitudes from 0 to 270 degrees.

python
import math

for deg in [0, 30, 90, 180, 270]:
    amp = math.sin(math.radians(deg))
    print(f"{deg:>3} deg -> {amp:+.4f}")

How It Works

  1. Convert degrees first. Calling math.radians(deg) turns each degree value into radians before passing to math.sin().
  2. Signed zero at 180. Formatting to four decimal places rounds away the tiny 1.22e-16 residual at 180 degrees.
  3. Full crest and trough. Ninety degrees reaches +1.0000 and 270 degrees drops to -1.0000.

Example 2 — Measure Roof Truss Peak Height From Span and Pitch

Compute vertical drop or gable rise along a sloped beam using length * math.sin(pitch).

python
import math

rafter_m = 6.0
for pitch_deg in [15, 30, 45]:
    rise = rafter_m * math.sin(math.radians(pitch_deg))
    print(f"pitch {pitch_deg} deg -> rise {rise:.2f} m")

How It Works

  1. Right-triangle projection. Opposite vertical height equals rafter hypotenuse times sine of the pitch angle.
  2. Thirty-degree half height. At 30 degrees, sine is half, giving exact 3.00 m rise on a 6.0 m rafter.
  3. Two-decimal blueprint output. Formatting with :.2f gives practical construction measurements.

Example 3 — Observe float pi Residuals and Infinity Domain Errors

Check math.sin(math.pi) against zero with math.isclose() and handle infinity.

python
import math

val = math.sin(math.pi)
print(val)
print(math.isclose(val, 0.0, abs_tol=1e-15))

try:
    math.sin(float("inf"))
except ValueError:
    print("sin(inf) raises ValueError")

How It Works

  1. Finite pi approximation. Because math.pi cannot represent irrational pi exactly, its sine is slightly above zero.
  2. Tolerance check passes. Comparing with abs_tol=1e-15 confirms the result is practically zero.
  3. No limit at infinity. Since sine oscillates forever, passing inf raises ValueError.

Frequently Asked Questions

Radians. Use math.sin(math.radians(deg)) when starting from degrees.
math.pi is rounded to 64-bit floating-point precision, so it differs slightly from true pi, leaving a tiny ~1.22e-16 residual.
It raises ValueError because sine has no limiting value at infinity.
math.asin(y) reverses sin(x) for angles in [-pi/2, pi/2].
Import cmath and call cmath.sin(z) instead of math.sin(z).

Next: math.sinh()

Return the hyperbolic sine of x as a float.

sinh() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful