Python Tutorial Python Advanced Python References Python Libraries

Python cmath - tanh() Function



The Python cmath.tanh() function returns the complex hyperbolic tangent of a complex number z. It is a function on complex plane, and has no branch cuts. It is periodic with respect to the imaginary component, with period 𝜋j, and has poles of the first order along the imaginary line, at coordinates (0, 𝜋(1/2 + n)). However no common floating-point representation is able to represent 𝜋/2 exactly.

Mathematically, it can be expressed as:

complex tanh

Syntax

cmath.tanh(z)

Parameters

z Required. Specify a number to find the complex hyperbolic tangent of

Return Value

Returns the complex hyperbolic tangent of z.

Example:

In the example below, tanh() function is used to find out the complex hyperbolic tangent of the given number.

import cmath

z1 = 2 + 2j
z2 = 2
z3 = 2j

print("cmath.tanh(z1):", cmath.tanh(z1))
print("cmath.tanh(z2):", cmath.tanh(z2))
print("cmath.tanh(z3):", cmath.tanh(z3))

The output of the above code will be:

cmath.tanh(z1): (1.0238355945704727-0.028392952868232294j)
cmath.tanh(z2): (0.9640275800758169+0j)
cmath.tanh(z3): -2.185039863261519j

❮ Python cMath Module