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 math tanh function returns TypeError.

Python tanh Function Example

The math 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.

TIP: Please refer to the Python tan article from the Python basics page to understand the Tangent Function.

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 Python Tuple and Python List items. If you observe the above screenshot, the Math tanh 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.

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'))
TANH Function

TIP: Please refer to the Python sinh and Python cosh functions from the list of Python math methods to find the hyperbolic sine and cosine values.