python math random

很有用个的工具

值得好好看看,这是作者(python发明者)对于工作中使用到的大多数场景的提炼

//test.py

1 import math
2
3 print abs(-10)
4 print math.ceil(4.1)
5 print cmp(1,2)
6 print math.exp(2)
7 print math.fabs(-10)
8 print math.log(math.e)
9 print math.log(100, 10)
10 print math.log10(100)
11 print max(1, 2)
12 print max((1, 2))
13 print max((1, 2), (3, 4))
14 print min(1,2)
15 print math.modf(-10.3456)
16 print math.pow(2, 2)
17 print round(1.4587604, 3)
18 print math.sqrt(4)
19
20 print math.acos(0.7)
21 print math.asin(0.7)
22 print math.atan(12)
23 print math.atan2(10, 3)
24 print math.hypot(2, 3)
25 print math.sin(30)
26 print math.tan(30)
27 print math.degrees(0.8)
28 print math.radians(90)
29 print math.radians(360)
30
31 import random
32
33 nums = (1, 2, 3, 4, 5)
34 print random.choice(nums)
35 print random.choice(range(100))
36 print random.randrange(100)
37 print random.randrange(0, 100, 3)
38 print random.random()
39 v_nums = list(nums)
40 random.shuffle(v_nums)
41 print v_nums
42 print random.uniform(10.3, 27.8)

//result

# python test.py
10
5.0
-1
7.38905609893
10.0
1.0
2.0
2.0
2
2
(3, 4)
1
(-0.34559999999999924, -10.0)
4.0
1.459
2.0
0.795398830184
0.775397496611
1.48765509491
1.27933953232
3.60555127546
-0.988031624093
-6.40533119665
45.8366236105
1.57079632679
6.28318530718
1
90
2
48
0.343898314122
[3, 2, 5, 1, 4]
13.7044793568

Finally:

需要时候,可以回来看一下这个例子,立马就能知道怎么用这些个函数了

转载于:https://www.cnblogs.com/woodzcl/p/7773435.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值