Python tan

The Python tan math function calculates the Trigonometry Tangent for the specified expression. In this section, we show how to use the Python tan function with an example.

The mathematical formula behind the Trigonometry Tangent function is the Length of the Opposite Side / Length of the Adjacent Side. The syntax of the Python tan Function is


Number: It can be a number or a valid numerical expression for which you want to find a Tangent value.

  • If the number argument is a positive or negative number, the Python tan function returns the Tangent value.
  • If the number argument is not a number, it returns TypeError.

Python tan Function Example

The Python tan Function allows you to find the trigonometry Tangent for the numeric values. In this example, we are going to find the Tangent values of different data types and display the output.

First, we declared List and Tuple with some random values. Next, we used the tan Function on both Positive integer and negative integer. The first two statements find the Tangent of the corresponding values.

Next, we used the Function on Tuple and List items. If you see the below screenshot, it works perfectly on them. Next, we used this math method on multiple numbers.

Within the last statement, we tried the tan Function on the String data, which returns TypeError as output.

TIP: Please refer to the atan article to find the Arc Tangent of the specified Python expression.

import math

Tup = (1, 2, 3, -4 , 5)
Lis = [-1, 2, -3.5, -4 , 5]

print('Tangent value of Positive Number = %.2f' %math.tan(10))
print('Tangent value of Negative Number = %.2f' %math.tan(-15))

print('Tangent value of Tuple Item = %.2f' %math.tan(Tup[3]))
print('Tangent value of List Item = %.2f' %math.tan(Lis[2]))

print('Tangent value of Multiple Number = %.2f' %math.tan(10 + 20 - 40))

print('Tangent value of String Number = ', math.tan('Hello'))
Python TAN Function