很有用个的工具

值得好好看看,这是作者(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:

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

python math random的更多相关文章

  1. 【转载】python 模块 - random生成随机数模块

    随机数种子 要每次产生随机数相同就要设置种子,相同种子数的Random对象,相同次数生成的随机数字是完全相同的: random.seed(1) 这样random.randint(0,6, (4,5)) ...

  2. Chrome V8引擎系列随笔 (1):Math.Random()函数概览

    先让大家来看一幅图,这幅图是V8引擎4.7版本和4.9版本Math.Random()函数的值的分布图,我可以这么理解 .从下图中,也许你会认为这是个二维码?其实这幅图告诉我们一个道理,第二张图的点的分 ...

  3. Math.random()

    Math.random() 日期时间函数(需要用变量调用):var b = new Date(); //获取当前时间b.getTime() //获取时间戳b.getFullYear() //获取年份b ...

  4. 如何在一个页面后面随机跳转到多个链接地址Math.floor()和Math.random()

    点击一个标签随机跳转到多个链接地址,主要运用javascript中的Math.floor()和Math.random()方法 floor(x) 方法是向下去整数 参数为任意数值或表达式. floor( ...

  5. 验证码点击刷新 this.src=this.src+'?'+Math.random()

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Random.nextint() 和Math.random()的区别

    Random.nextint() 和Math.random()的区别 Java代码   Random rand = new Random(); long startTime = System.nano ...

  7. js中Math.random()生成指定范围数值的随机数

    http://www.111cn.net/wy/js-ajax/57062.htm Math.random() 这个方法相信大家都知道,是用来生成随机数的.不过一般的参考手册时却没有说明如何用这个方法 ...

  8. javascript 中根据sort 方法随机数组 (Math.random)

    var arr = [1,2,3,4,5,6,7,8,9,10]; function Arandom(a,b){ return (Math.random() > 0.5) ? 1 : -1;; ...

  9. python使用random函数生成随机数

    python使用random函数来生成随机数,常用的方法有: import random #生成0-1之间的数(不包括0和1) random.random() #生成1-5之间的随机整数(包括1和5) ...

随机推荐

  1. np.unravel_index

      >>> np.unravel_index([22, 41, 37], (7,6)) (array([3, 6, 6]), array([4, 5, 1]))>>> ...

  2. 洛谷P1403 约数研究【思维】

    题目:https://www.luogu.org/problemnew/show/P1403 题意: 定义$f(n)$为n的因子个数.给定一个数n,求$f(1)$到$f(n)$之和. 思路: 最直接的 ...

  3. 洛谷试炼场-简单数学问题-P1088 火星人

    洛谷试炼场-简单数学问题 A--P1088 火星人 Description 人类终于登上了火星的土地并且见到了神秘的火星人.人类和火星人都无法理解对方的语言,但是我们的科学家发明了一种用数字交流的方法 ...

  4. [No0000173]97 条 Linux 常用命令总结

    1.ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a  列出包括.a开头的隐藏文件的所有文件-A  通-a,但不列出"."和".."-l  列 ...

  5. springboot程序无法访问静态资源

    今天开发遇到了一个很奇葩的错误,再spngboot程序成功运行后发现无法访问再resouces/static下的静态资源,通过rul访问总是404,原因最终锁定在某配置类的一个标签上: @Enable ...

  6. 1.7Oob 方法体中的循环也能也能返回值给方法

    public String monthString(int monthNumber){ switch(monthNumber){ case 1: return "january"; ...

  7. CSS 小技巧

    CSS 小技巧 一.边框内圆角 我们在设计例如按钮等控件的时候,会遇到这样的设计:只有内侧有圆角,而边框或者描边的四个角还是保持直角的形状,用以下代码可以轻松的实现. #wrapper { width ...

  8. tomcat远程部署war包,显示连接被重置

    在tomcat 目录: /opt/apache-tomcat-9.0.13/webapps/manager/WEB-INF/web.xml 下修改: <multipart-config> ...

  9. post/get in console of JSarray/js 数组详细操作方法及解析合集

    https://juejin.im/post/5b0903b26fb9a07a9d70c7e0[ js 数组详细操作方法及解析合集 js array and for each https://blog ...

  10. hadoop 学习笔记2

    ============Hive vs Hadoop============== Hive是建立在Hadoop之上为了减少MapReduce jobs编写工作的批处理系统,HBase是为了支持弥补Ha ...