很有用个的工具

值得好好看看,这是作者(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. SQL多结果集导出Excel

    由于本项目工作中需要,有时会导出一些数据给客户,但又不是每次都需要,可能这次用了下次可能就不会使用,导出数据,我们正在做的一个项目中与四川地区有关,所以导出数据就有如下需求: 1.  按各市导出数据, ...

  2. BZOJ 1002 - 轮状病毒 - [基尔霍夫矩阵(待补)+高精度]

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1002 Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生 ...

  3. FutureTask的用法及两种常用的使用场景

    FutureTask可用于异步获取执行结果或取消执行任务的场景.通过传入Runnable或者Callable的任务给FutureTask,直接调用其run方法或者放入线程池执行,之后可以在外部通过Fu ...

  4. 基于Gogs+Drone搭建的私有CI/CD平台

    请移步 基于Gogs+Drone搭建的私有CI/CD平台

  5. 快速安装elkstack

    一.介绍 The Elastic Stack - 它不是一个软件,而是Elasticsearch,Logstash,Kibana 开源软件的集合,对外是作为一个日志管理系统的开源方案.它可以从任何来源 ...

  6. 拦截器的作用之session认证登录和资源拦截

    背景: 在项目中我使用了自定义的Filter 这时候过滤了很多路径,当然对静态资源我是直接放过去的,但是,还是出现了静态资源没办法访问到springboot默认的文件夹中得文件.另外,经常需要判断当前 ...

  7. 第5章 实现windows程序的数据绑定

    1:连接式: command 对象负责对数据库的执行命令 DataReader 对象负责从数据源中读取数据 connection 对象负责链接数据库 断开式: 数据集的Dataset存放在独立的数据源 ...

  8. 前端用Json传输数据给后台,用postman测试

    postman发送json格式的post请求   在地址栏里输入请求url:http://127.0.0.1:8081/getmoney 选择“POST”方式, 在“headers”添加key:Con ...

  9. c语言指针应用

    指针变量指向数组元素: #import <stdio.h> int main() { int a[10]={1,2,3,4,5,6,7,8,9,0}; int *p; p=a; for ( ...

  10. jquery实现简单的弹出框

    弹出框本身是一个div,默认是隐藏不展示的,在需要弹框的时候使其显示,并浮在当前页面之上 弹框样式: .tanchuang { width: 100%; height: 100%; display: ...