Python 中的数学函数 - 特殊函数和常量
在本文中,我们将学习 Python 标准库中 math 模块中可用的特殊函数和常量。
这里我们将讨论一些常数,例如−
- pi
- e
- inf
- Nan
- tau
以及一些函数,例如
- Gamma
- Isinf
- Isnan
- isfinite()
- erf()
我们来讨论一下常数及其各自的值 −
| pi | 3.141592….. |
| e | 2.718281…... |
| inf | 6.283185…... |
| nan | <infinty> |
| tau | <not a number> |
现在让我们讨论一些特殊函数及其实现−
Gamma − 返回 gamma(n) 的值
Isinf − 检查函数的值是否为无穷大。
Isnan − 检查返回值是否为数字。
Isfinite − 如果该值既不是无穷大也不是 nan 则返回 True,否则返回 false
Erf − 返回 x 的误差函数。
现在让我们看一个示例−
示例
import math
num=10
print (math.gamma(num))
if (math.isnan(math.nan)):
print ("The number is not a number")
else : print ("The number is a number")
if (math.isinf(math.inf)):
print ("The number is positive infinity")
else : print ("The number is not positive infinity")
print(math.isfinite(math.inf))输出
362880.0 The number is not a number The number is positive infinity False
结论
在本文中,我们学习了 Python 中的数学函数 - 特殊函数和常量。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP