math.cosh()方法是数学模块的一种库方法,用于获取以弧度为单位的给定数字的双曲余弦值,它接受一个数字并返回双曲余弦值。
注意: math.cosh()方法仅接受数字,如果我们提供除数字以外的其他任何内容,它将返回错误TypeError – “ TypeError:需要浮点数”。
它的语法 math.cosh() 方法:
math.cosh(x)
Parameter(s): x –是要计算其双曲余弦的数字。
返回值: float-它返回一个浮点值,它是数字x的双曲余弦值。
示例
Input: x = 1.5 # 函数调用 print(math.cosh(x)) Output: 2.352409615243247
# Python代码演示示例
# math.cosh() method
# 导入数学模块
import math
# 数
x = -10
print("math.cosh(",x,"): ", math.cosh(x))
x = 0
print("math.cosh(",x,"): ", math.cosh(x))
x = 1.5
print("math.cosh(",x,"): ", math.cosh(x))
x = 5
print("math.cosh(",x,"): ", math.cosh(x))
x = 15.45
print("math.cosh(",x,"): ", math.cosh(x))输出结果
math.cosh( -10 ): 11013.232920103324 math.cosh( 0 ): 1.0 math.cosh( 1.5 ): 2.352409615243247 math.cosh( 5 ): 74.20994852478785 math.cosh( 15.45 ): 2563419.889913628
TypeError示例
# Python代码演示示例
# math.cosh() method with exception
# 导入数学模块
import math
# 数
x = "2.5"
print("math.cosh(",x,"): ", math.cosh(x))输出结果
Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("math.cosh(",x,"): ", math.cosh(x))
TypeError: a float is required