python path库
HeTaoBianCheng
·
·
学习·文化课
Python的math库提供了丰富的数学运算函数,以下是常用函数的分类总结:
注:使用前请先使用from math import *导入模块!
| 格式 |
相当于 |
解释 |
ceil(x) |
\lceil x \rceil |
将x向上取整 |
floor(x) |
\lfloor x \rfloor |
将x向下取整 |
pow(x,y) |
x^y |
x的y次方 |
sqrt(x) |
\sqrt x |
计算根号x |
exp(x) |
\mathrm{e}^x |
计算e的x次方 |
sin(x) |
\sin x |
\sin x |
cos(x) |
\cos x |
\cos x |
tan(x) |
\tan x |
\tan x |
asin(x) |
\arcsin x |
\arcsin x |
acos(x) |
\arccos x |
\arccos x |
atan(x) |
\arctan x |
\arctan x |
degrees(x) |
\operatorname{deg}(x) |
将角度x转换为弧度 |
radians(x) |
\operatorname{rad}(x) |
将弧度x转为角度 |
factorial(x) |
x!(x \times (x - 1) \times (x - 1) \times \cdots \times 1) |
计算x的阶乘 |
gcd(a,b) |
\gcd(a,b) |
计算a和b的最大公约数 |
lcm(a,b) |
\operatorname{lcm}(a,b) |
计算a和b的最小公倍数 |
fsum(nums) |
nums[1] + nums[2] + \cdots + nums[-1] |
高精度计算nums中所有数字和 |
modf(x) |
(\lfloor x \rfloor,x \bmod 1) |
把x的整数部分和小数部分存储到一个元组里 |
copysign(x,y) |
\lvert x \rvert \cdot \operatorname{sign}(y) |
\lvert x \rvert \cdot \operatorname{sign}(y) |
下面的请先使用import math导入模块,且以下可以直接使用: |
格式 |
相当于 |
解释 |
math.pi |
\pi |
圆周率 \pi |
math.e |
\mathrm{e} |
自然对数底数 \mathrm{e} |
math.inf |
\infty(实际输出:inf) |
无穷大 |