typora/note/Python/数学函数.md

48 lines
5.6 KiB
Markdown
Raw Permalink Normal View History

2024-12-11 21:48:55 -05:00
### 数学运算函数
| 函数 | 返回值 ( 描述 ) |
| :----------------------------------------------------------- | :----------------------------------------------------------- |
| [abs(x)](https://www.w3cschool.cn/python3/python3-func-number-abs.html) | 返回数字的绝对值如abs(-10) 返回 10 |
| [ceil(x)](https://www.w3cschool.cn/python3/python3-func-number-ceil.html) | 返回数字的上入整数如math.ceil(4.1) 返回 5 |
| cmp(x, y) | 如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1。 **Python 3 已废弃,使用 (x>y)-(x<y) 替换**。 |
| [exp(x)](https://www.w3cschool.cn/python3/python3-func-number-exp.html) | 返回e的x次幂(ex),如math.exp(1) 返回2.718281828459045 |
| [fabs(x)](https://www.w3cschool.cn/python3/python3-func-number-fabs.html) | 返回数字的绝对值如math.fabs(-10) 返回10.0 |
| [floor(x)](https://www.w3cschool.cn/python3/python3-func-number-floor.html) | 返回数字的下舍整数如math.floor(4.9)返回 4 |
| [log(x)](https://www.w3cschool.cn/python3/python3-func-number-log.html) | 如math.log(math.e)返回1.0,math.log(100,10)返回2.0 |
| [log10(x)](https://www.w3cschool.cn/python3/python3-func-number-log10.html) | 返回以10为基数的x的对数如math.log10(100)返回 2.0 |
| [max(x1, x2,...)](https://www.w3cschool.cn/python3/python3-func-number-max.html) | 返回给定参数的最大值,参数可以为序列。 |
| [min(x1, x2,...)](https://www.w3cschool.cn/python3/python3-func-number-min.html) | 返回给定参数的最小值,参数可以为序列。 |
| [modf(x)](https://www.w3cschool.cn/python3/python3-func-number-modf.html) | 返回x的整数部分与小数部分两部分的数值符号与x相同整数部分以浮点型表示。 |
| [pow(x, y)](https://www.w3cschool.cn/python3/python3-func-number-pow.html) | x**y 运算后的值。 |
| [round(x [,n\])](https://www.w3cschool.cn/python3/python3-func-number-round.html) | 返回浮点数 x 的四舍五入值,如给出 n 值,则代表舍入到小数点后的位数。**其实准确的说是保留值将保留到离上一位更近的一端。** |
| [sqrt(x)](https://www.w3cschool.cn/python3/python3-func-number-sqrt.html) | 返回数字x的平方根。 |
### 随机数函数
| 函数 | 描述 |
| :----------------------------------------------------------- | :----------------------------------------------------------- |
| [choice(seq)](https://www.w3cschool.cn/python3/python3-func-number-choice.html) | 从序列的元素中随机挑选一个元素比如random.choice(range(10))从0到9中随机挑选一个整数。 |
| [randrange ([start,\] stop [,step])](https://www.w3cschool.cn/python3/python3-func-number-randrange.html) | 从指定范围内,按指定基数递增的集合中获取一个随机数,基数默认值为 1 |
| [random()](https://www.w3cschool.cn/python3/python3-func-number-random.html) | 随机生成下一个实数,它在[0,1)范围内。 |
| [seed([x\])](https://www.w3cschool.cn/python3/python3-func-number-seed.html) | 改变随机数生成器的种子seed。如果你不了解其原理你不必特别去设定seedPython会帮你选择seed。 |
| [shuffle(list)](https://www.w3cschool.cn/python3/python3-func-number-shuffle.html) | 将序列的所有元素随机排序 |
| [uniform(x, y)](https://www.w3cschool.cn/python3/python3-func-number-uniform.html) | 随机生成下一个实数,它在[x,y]范围内。 |
### 三角函数
| 函数 | 描述 |
| :----------------------------------------------------------- | :------------------------------------------------ |
| [acos(x)](https://www.w3cschool.cn/python3/python3-func-number-acos.html#) | 返回x的反余弦弧度值。 |
| [asin(x)](https://www.w3cschool.cn/python3/python3-func-number-asin.html) | 返回x的反正弦弧度值。 |
| [atan(x)](https://www.w3cschool.cn/python3/python3-func-number-atan.html) | 返回x的反正切弧度值。 |
| [atan2(y, x)](https://www.w3cschool.cn/python3/python3-func-number-atan2.html) | 返回给定的 X 及 Y 坐标值的反正切值。 |
| [cos(x)](https://www.w3cschool.cn/python3/python3-func-number-cos.html) | 返回x的弧度的余弦值。 |
| [hypot(x, y)](https://www.w3cschool.cn/python3/python3-func-number-hypot.html) | 返回欧几里德范数 sqrt(x*x + y*y)。 |
| [sin(x)](https://www.w3cschool.cn/python3/python3-func-number-sin.html) | 返回的x弧度的正弦值。 |
| [tan(x)](https://www.w3cschool.cn/python3/python3-func-number-tan.html) | 返回x弧度的正切值。 |
| [degrees(x)](https://www.w3cschool.cn/python3/python3-func-number-degrees.html) | 将弧度转换为角度,如degrees(math.pi/2) 返回90.0 |
| [radians(x)](https://www.w3cschool.cn/python3/python3-func-number-radians.html) | 将角度转换为弧度 |