Python tanh

Python tanh math function calculates the trigonometric hyperbolic tangent of a given expression, and the syntax of it is

math.tanh(number);

Number: It can be a number or a valid numerical expression for which you want to find a hyperbolic Tangent value. If it is not a number, the Python tanh function returns TypeError.

Python tanh Function Example

The Python tanh Function allows you to find the trigonometric Hyperbolic tangent for numeric values. In this example, we are going to find the hyperbolic tangent values for different data types and display the output.

First, we used the tanh Function directly on both Positive and negative integers. The following statements find the hyperbolic Tangent of the corresponding values.

Next, We used the Function on Tuple and List items. If you observe the above screenshot, the Math function is working perfectly on them. Next, We used it directly on multiple values.

Within the last statement, we tried on the String value, and it returns TypeError.

TIP: Please refer to the tan article to understand the Tangent Function.

import math

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

print('Hyperbolic Tangent value of Positive Number = %.2f' %math.tanh(1))
print('Hyperbolic Tangent value of Negative Number = %.2f' %math.tanh(-2))

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

print('Hyperbolic Tangent of Multiple Numbers = %.2f' %math.tanh(2 + 9 - 7))

print('Hyperbolic Tangent value of String Value = ', math.tanh('Hello'))
Python TANH Function