python math模块

import math

math.

ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x

copysign:把y的正负号加到x前面,可以使用0

cos:求x的余弦,x必须是弧度

degrees:把x从弧度转换成角度

e:表示一个常量

exp:返回math.e,也就是2.71828的x次方

expm1:返回math.e的x(其值为2.71828)次方的值减1

fabs:返回x的绝对值

factorial:取x的阶乘的值

floor:取小于等于x的最大的整数值,如果x是一个整数,则返回自身

fmod:得到x/y的余数,其值是一个浮点数

frexp:返回一个元组(m,e),其计算方式为:x分别除0.5和1,得到一个值的范围

fsum:对迭代器里的每个元素进行求和操作

gcd:返回x和y的最大公约数

hypot:如果x是不是无穷大的数字,则返回True,否则返回False

isfinite:如果x是正无穷大或负无穷大,则返回True,否则返回False

isinf:如果x是正无穷大或负无穷大,则返回True,否则返回False

isnan:如果x不是数字True,否则返回False

ldexp:返回x*(2**i)的值

log:返回x的自然对数,默认以e为基数,base参数给定时,将x的对数返回给定的base,计算式为:log(x)/log(base)

log10:返回x的以10为底的对数

log1p:返回x+1的自然对数(基数为e)的值

log2:返回x的基2对数

modf:返回由x的小数部分和整数部分组成的元组

pi:数字常量,圆周率

pow:返回x的y次方,即x**y

radians:把角度x转换成弧度

sin:求x(x为弧度)的正弦值

sqrt:求x的平方根

tan:返回x(x为弧度)的正切值

trunc:返回x的整数部分

代码:

 1 >>> import math
 2 >>> math.ceil(2.33)
 3 3
 4 >>> math.copysign(2, -4)
 5 -2.0
 6 >>> math.cos(math.pi/3)
 7 0.5000000000000001
 8 >>> math.degrees(math.pi/3)
 9 59.99999999999999
10 >>> math.e
11 2.718281828459045
12 >>> math.exp(1)
13 2.718281828459045
14 >>> math.expm1(1)
15 1.718281828459045
16 >>> math.fabs(-2)
17 2.0
18 >>> math.factorial(3)
19 6
20 >>> math.floor(2.7356)
21 2
22 >>> math.fmod(8, 5)
23 3.0
24 >>> math.frexp(10)
25 (0.625, 4)
26 >>> math.fsum([1, 3, 5, 7, 9])
27 25.0
28 >>> math.gcd(12, 16)
29 4
30 >>> math.hypot(3, 4)
31 5.0
32 >>> math.isfinite(0/1)
33 True
34 >>> math.isinf(222)
35 False
36 >>> math.isnan(22)
37 False
38 >>> math.ldexp(5, 2)
39 20.0
40 >>> math.log(10)
41 2.302585092994046
42 >>> math.log(math.e)
43 1.0
44 >>> math.log10(100)
45 2.0
46 >>> math.log(10)
47 2.302585092994046
48 >>> math.log1p(10)
49 2.3978952727983707
50 >>> math.log(11)
51 2.3978952727983707
52 >>> math.log2(1024)
53 10.0
54 >>> math.log2(16)
55 4.0
56 >>> math.modf(math.pi)
57 (0.14159265358979312, 3.0)
58 >>> math.pi
59 3.141592653589793
60 >>> math.pow(3, 4)
61 81.0
62 >>> math.radians(45)
63 0.7853981633974483
64 >>> math.sin(math.pi/3)
65 0.8660254037844386
66 >>> math.sqrt(16)
67 4.0
68 >>> math.tan(math.pi/4)
69 0.9999999999999999
70 >>> math.trunc(2.56789)
71 2
72 >>> math.trunc(-2.56789)
73 -2
View Code

 

posted on 2018-04-19 11:23  Guo磊  阅读(156)  评论(0编辑  收藏  举报

导航