您的位置:首页 > 编程语言 > Python开发

(9)python数字常用函数

2015-11-06 03:17 525 查看
声明:学习笔记,无任何意义。

'绝对值:'
>>> print(abs(-10))
10
'返回整数:'
>>> import math
>>> math.ceil(1.02212354)
2
>>> math.ceil(math.pi)
4
>>> "反馈指数:"
'反馈指数:'
>>> import math
>>> math.exp(1.111)
3.0373942705151613
>>> math.exp(4)
54.598150033144236
>>> math.exp(100)
2.6881171418161356e+43
'返回绝对值:'
>>> math.fabs(-123)
123.0
'floor() 返回数字的下舍整数:'
>>> math.floor(2.345)
2
>>> math.floor(-45.123)
-46
>>> math.floor(-1.001)
-2
>>> math.floor(-math.pi)
-4
>>> math.floor(math.pi)
3
'log() 方法返回x的自然对数。:'
>>> math.log(100)
4.605170185988092
>>> "log10() 方法返回以10为基数的x对数:"
'log10() 方法返回以10为基数的x对数:'
>>> math.log10(10)
1.0
>>> math.log10(100)
2.0
'max() 方法返回给定参数的最大值,参数可以为序列:'
>>> max(1,2,3,4)
4
>>> list1 = [100,20,566]
>>> list2 = [150,160,180]
>>> list3 = [200,1,666]
>>> max(list1)
566
>>> max(list1,list2,list3)
[200, 1, 666]
'min() 方法返回给定参数的最小值,参数可以为序列:'
>>> min(list1,list2,list3)
[100, 20, 566]
'modf() 方法返回x的整数部分与小数部分,两部分的数值符号与x相同,整数部分以浮点型表示:'
>>> math.modf(1.125)
(0.125, 1.0)
>>> math.modf(98.666)
(0.6659999999999968, 98.0)
'pow() 方法返回 xy(x的y次方) 的值:'
>>> math.pow(2,2)
4.0
>>> math.pow(-4,3)
-64.0
>>> math.pow(6,-2)
0.027777777777777776
'round() 方法返回浮点数x的四舍五入值:'
>>> round(1.123456789,3)
1.123
>>> round(3.015,2)
3.02
'sqrt() 方法返回数字x的平方根:'
>>> math.sqrt(2)
1.4142135623730951
>>> random.choice("abcdef")
'a'
>>> random.choice((1,'2',1.023))
'2'
'randrange() 方法返回指定递增基数集合中的一个随机数,基数缺省值为1:'
>>> random.randrange(1,10,2)
9
>>> random.randrange(1,10,3)
4
'random() 方法返回随机生成的一个实数,它在[0,1)范围内:'
>>> random.random()
0.4421531199997717
>>> random.random()
0.4291585256761331
'seed() 方法改变随机数生成器的种子,可以在调用其他随机模块函数之前调用此函数:'
>>> random.seed(1)
>>> random.random()
0.13436424411240122
'shuffle() 方法将序列的所有元素随机排序:'
>>> random.shuffle(list1)
>>> list1
[100, 566, 20]
>>> random.shuffle(list1)
>>> list1
[566, 100, 20]
>>> random.shuffle(list1)
>>> list1
[20, 100, 566]
'uniform() 方法将随机生成下一个实数,它在[x,y]范围内:'
>>> random.uniform(0,15)
12.199818770359801
'acos() 返回x的反余弦弧度值:'
>>> math.acos(1)
0.0
>>> math.acos(0)
1.5707963267948966
'asin() 返回x的反正弦弧度值:'
>>> math.asin(-1)
-1.5707963267948966
'atan() 返回x的反正切弧度值:'
>>> math.atan(-1)
-0.7853981633974483
'atan2() 返回给定的 X 及 Y 坐标值的反正切值:'
>>> math.atan2(-1,50)
-0.01999733397315053
>>> math.atan2(1,0)
1.5707963267948966
'cos() 返回x的弧度的余弦值:'
>>> math.cos(1)
0.5403023058681398
>>> math.cos(math.pi*2)
1.0
'hypot() 返回欧几里德范数 sqrt(x*x + y*y):'
>>> math.hypot(0,0)
0.0
>>> math.hypot(0,1)
1.0
>>> math.hypot(1,1)
1.4142135623730951
'sin() 返回的x弧度的正弦值:'
>>> math.sin(0)
0.0
>>> math.sin(-1)
-0.8414709848078965
>>> math.sin(1)
0.8414709848078965
>>> math.sin(1.1)
0.8912073600614354
>>> math.sin(2)
0.9092974268256817
>>> math.sin(0.1)
0.09983341664682815
'tan() 返回x弧度的正弦值:'
>>> math.tan(0.1)
0.10033467208545055
>>> math.tan(1)
1.5574077246549023
>>> math.tan(math.pi*3/2)
5443746451065123.0
'degrees() 将弧度转换为角度:'
>>> math.degrees(10)
572.9577951308232
>>> math.degrees(1)
57.29577951308232
'radians() 方法将角度转换为弧度:'
>>> math.radians(572.9577951308232)
10.0
>>> math.radians(5443746451065123.0)
95011299214842.77
数字常量:
>>> math.e
2.718281828459045
>>> math.pi
3.141592653589793
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: