Python math.tanh() Method

Python math 模块Python math Module

Python math.tanh(x)Returns the hyperbolic tangent of x.

Python Version: 1.4

Syntax

The syntax of the math.tanh() method is as follows:

math.tanh(x)

Parameter description:

  • xx -- Required, a positive or negative number. If x is not a number, TypeError is returned.

Return Value

Returns a floating-point number representing the hyperbolic tangent of a number.

Example

The following examples return the hyperbolic tangent of different numbers:

Example

# Import the math package
import math

# Output the hyperbolic tangent value
print(math.tanh(8))
print(math.tanh(1))
print(math.tanh(-6.2))

Output result:

0.9999997749296758
0.7615941559557649
-0.9999917628565104

Python math 模块Python math Module

Other Extensions