Python cosh 函数用于计算指定表达式的三角双曲余弦值。在本节中,我们将通过示例讨论如何使用 cosh 函数。该编程语言中 cosh 函数的语法如下所示。
math.cosh(number);
Number: 它可以是数字或您想找到双曲余弦值的有效数值表达式。
- 如果数字参数是正数或负数,则函数返回双曲余弦值。
- 如果数字参数不是数字,则返回 TypeError。
Python cosh 函数示例
cosh 函数允许您查找数值的双曲余弦值。在此示例中,我们将查找不同数据类型的双曲余弦值并显示输出。
提示:请参阅 cos 函数文章以了解余弦函数。
import math
Tup = (1, 2, 3, -4 , 5)
Lis = [-1, 2, -3.5, -4 , 5]
print('Hyperbolic Cosine value of Positive Number = %.2f' %math.cosh(1))
print('Hyperbolic Cosine value of Negative Number = %.2f' %math.cosh(-2))
print('Hyperbolic Cosine value of Tuple Item = %.2f' %math.cosh(Tup[3]))
print('Hyperbolic Cosine value of List Item = %.2f' %math.cosh(Lis[2]))
print('Hyperbolic Cosine value of Multiple Numbers = %.2f' %math.cosh(2 + 9 - 7))
print('Hyperbolic Cosine value of String Value = ', math.cosh('Hello'))

首先,我们直接对正整数和负整数使用了 Python cosh 函数。以下 Python 语句可查找相应值的双曲余弦。
print('Hyperbolic Cosine value of Positive Number = %.2f' %math.cosh(1))
print('Hyperbolic Cosine value of Negative Number = %.2f' %math.cosh(-2))
接下来,我们将此双曲余弦函数用于 元组 和 列表 项。如果您观察上面的截图,它在这些项目上工作得很好。
print('Hyperbolic Cosine value of Tuple Item = %.2f' %math.cosh(Tup[3]))
print('Hyperbolic Cosine value of List Item = %.2f' %math.cosh(Lis[2]))
接下来,我们直接将 math 函数 用于多个值。
print('Hyperbolic Cosine value of Multiple Numbers = %.2f' %math.cosh(2 + 9 - 7))
在最后一个语句中,我们尝试将 cosh 函数用于字符串值,这会返回 TypeError。
print('Hyperbolic Cosine value of String Value = ', math.cosh('Hello'))