Python tanh 数学函数计算给定表达式的双曲正切值,其语法如下:
math.tanh(number);
Number:可以是数字或用于查找双曲正切值的有效数值表达式。如果不是数字,math tanh 函数将返回 TypeError。
Python tanh 函数示例
math tanh 函数允许您查找数值的双曲正切值。在此示例中,我们将查找不同数据类型的双曲正切值并显示输出。
首先,我们直接对正整数和负整数使用了 tanh 函数。以下语句计算相应值的双曲正切值。
接下来,我们对 元组 和 列表 项目使用了该函数。如果您观察上面的截图,数学函数在它们上面工作正常。接下来,我们直接对多个值使用了它。
在最后一个语句中,我们尝试使用了字符串值,它返回了 TypeError。请参阅 tan 文章以了解切线函数。
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'))
