The tanh()
function in Python returns a number’s hyperbolic tangent. To be more specific, it returns the hyperbolic tangent of a number in radians.
Figure 1 shows the mathematical representation of the tanh()
function.
Note: The
math
module is required for this function.
tanh(num)
This function requires a number
that represents an angle
in radians
as a parameter.
To convert degrees
to radians
, use:
radians = degrees * ( PI / 180.0 )
tanh()
returns the hyperbolic tangent
of a number (radians)
that is set as a parameter.
import math#positive number in radiansprint "The value of tanh(2.3) : ", math.tanh(2.3)#negative number in radiansprint "The value of tanh(-2.3) : ", math.tanh(-2.3)#converting the degrees angle into radians and then applying tanh()#degrees = 45#PI = 3.14159265result = 45.0 * (math.pi / 180.0)print "The value of tanh("+str(result)+") : ", math.tanh(result)