20210429 python笔记 数学函数与随机数
发布于 2021-04-29 23:56 ,所属分类:数学资料学习库
python还有 平方根函数,以及三角函数。这些用法在实践中涉及到运算就可以用。
u = math.sqrt(9)
print(u)
3.0
三角函数:
t = math.sin(math.radians(67))
print(t)
这里可以使用radians()函数把角度值转换为弧度值。
三角函数的反三角函数asin(),acos(),atan()等的返回值是弧度值,而非角度值。可以用degrees()函数把弧度值转换为角度值。
y = math.degrees(math.asin(0.707))
print(y)
44.991348337162016
随机数
randint(a,b)函数,生成一个指定范围内的整数,生成的随机数范围是a<=n<=b.
i = random.randint(1,10)
print(i)
这里和scratch中的随机数是一致的。
python random()这个不添加任何参数的情况下,可以随机生成0到1之间的随机数。
h = random.random()
print(h)
0.14174368008487692
每次生成的随机数都不一致。
random.uniform(1,10)这个函数可以生成一个随机浮点数。
e = random.uniform(210,220)
print(e)
218.74433079672167
randrange([start],stop,[step])指定区间范围,然后让一定的基数递增的集合中获取一个随机数。
g = random.randrange(10,20,3)
print(g)
13
对于已经有的列表的数值,可以通过shuffle()函数,进行一次随机的排序。
j = [1,2,3,4,5,6,7,8,9]
random.shuffle(j)
print(j)
[8, 6, 7, 9, 4, 1, 2, 3, 5]
random.choice()从列表中选出随机数,
k = ("shitou","jiandao","bu")
l = random.choice(k)
print(l)
bu















![[Python] python web开发视频教程51集(基础+函数+实例)](https://static.kouhao8.com/sucaidashi/xkbb/7ae6c7e3e4fe91fc43ad7a9f3c1f08a3.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)





![[Python爬虫] Python两套专题培训视频教程 Python自定义函数+Python培训之图片下载爬虫](https://static.kouhao8.com/sucaidashi/xkbb/c5d2bb19e1f9dd55f599179051f766e3.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)
![[Python爬虫] Python两套专题培训视频教程 Python自定义函数+Python培训之图片下载爬虫](https://static.kouhao8.com/sucaidashi/xkbb/40e6fd07991b797c294a1efa0fc5662a.png?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)
![[Python] Python自定义函数+Python培训之图片下载爬虫 Python两套专题培训视频教程](https://static.kouhao8.com/sucaidashi/xkbb/d5dd3afb5e3eb118e73400dda8792c48.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)








相关资源