Python – cmath.tanh()函数
cmath是用于复数数学的Python内置模块。 cmath 模块有一个方法 tanh(),它返回传递给它的复数的双曲正切。
Syntax: cmath.tanh(Z)
Parameter: It requires only one parameter i.e the number for which hyperbolic tangent needs to be calculated.
Return: Returns a complex number that is the hyperbolic tangent of the number passed.
示例 1:
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tanh(1 + 5j))
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tanh(1))
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tanh())
输出:
(1.2407479829240697-0.18610947764730415j)
示例 2:在此示例中传递了实数,但返回的结果仍然是复数。
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tanh(1))
输出:
(0.7615941559557649+0j)
示例 3:在此示例中,在这种情况下不传递任何参数,TypeError 将被抛出
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tanh())
输出:
TypeError: tanh() takes exactly one argument (0 given)