all Python 3mathterm
math.tan
trigonometry
Returns the tangent of an angle given in radians. math.tan(math.pi/4) ≈ 1.0. It is undefined at x = π/2 + πn.
Syntax
math.tan(x)
At the discontinuity Python neither raises nor returns inf: math.pi/2 is only an approximation of the true π/2, so math.tan(math.pi/2) yields a huge finite number around 1.6e16. There is no exception to catch, so if the discontinuity matters, screen the argument yourself before calling. Near π/2 the answer is inherently unreliable anyway: nudging the input by 1e-16 changes it by orders of magnitude.
Examples
import math
print(math.tan(0)) # → 0.0
print(math.tan(math.pi/4)) # → ? (значение зависит от системной libm — карточка учит наличию погрешности, а не её цифрам)
print(round(math.tan(math.pi/6), 4)) # → 0.5774
print(math.tan(math.pi)) # → ? (значение зависит от системной libm — карточка учит наличию погрешности, а не её цифрам)
print(math.tan(-math.pi/4)) # → ? (значение зависит от системной libm — карточка учит наличию погрешности, а не её цифрам)
print(round(math.tan(1), 4)) # → 1.5574
See also
Open in the full glossarydocs.python.orgReport an inaccuracy