Python math.sin() function


The math.sin() function in Python is used to calculate the sine of a given angle. The angle must be provided in radians, and the function returns the sine value as a float. The sine function is a fundamental mathematical function in trigonometry, often used in physics, engineering, and computer graphics.

Syntax

import math result = math.sin(x)
  • x: The angle in radians for which you want to calculate the sine.

Return Value

  • Returns the sine of the angle x as a float. The result will be in the range [1,1][-1, 1].

Examples

  1. Calculating the sine of an angle in radians:

    import math result = math.sin(math.pi / 2) # Sine of 90 degrees (π/2 radians) print(result) # Output: 1.0
  2. Calculating the sine of other angles:

    result = math.sin(math.pi) # Sine of 180 degrees (π radians) print(result) # Output: 0.0 result = math.sin(0) # Sine of 0 degrees (0 radians) print(result) # Output: 0.0 result = math.sin(-math.pi / 2) # Sine of -90 degrees (-π/2 radians) print(result) # Output: -1.0
  3. Using math.sin() with angles in degrees: If you have an angle in degrees, you can convert it to radians using math.radians() before calculating the sine:

    angle_deg = 30 result = math.sin(math.radians(angle_deg)) # Sine of 30 degrees print(result) # Output: 0.49999999999999994 (approximately 1/2)
  4. Using math.sin() in expressions: You can use math.sin() in more complex calculations:

    angle_rad = math.pi / 4 # 45 degrees result = math.sin(angle_rad) ** 2 + math.sin(angle_rad) ** 2 print(result) # Output: 1.0 (because sin(45)^2 + sin(45)^2 = 1)

Summary

  • The math.sin() function computes the sine of an angle in radians.
  • The result is always a float and lies within the range of [1,1][-1, 1].
  • This function is essential in trigonometry and is widely used in various applications, including physics, engineering, and computer graphics, where waveforms and periodic functions are involved.