import math
math.e
2.718281828459045
math.sqrt(4)
2.0
math.log10(1000)
3.0
math.log(math.e)
1.0
math.ceil(2.8)
3
math.ceil(-2.8)
-2
math.floor(2.8)
2
math.floor(-2.8)
-3
math.pi
3.141592653589793
import random
# 0-1之间的随机浮点数
random.random()
0.5005185452251253
# 给定范围的随机整数
random.randint(5,10)
8
# 从样本中随机选择
order_volumes = [2,10,14,18,20]
random.choice(order_volumes)
20
# 打乱已有样本
l = list(range(10))
l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
random.shuffle(l)
l
[5, 0, 6, 4, 7, 1, 8, 3, 2, 9]
这篇博客展示了Python在数学运算和随机数生成方面的应用。通过`math`库进行数学计算,如求自然对数、平方根和对数;使用`random`模块生成随机浮点数和整数,以及从列表中随机选择元素和打乱列表顺序。这些功能在数据分析、模拟和游戏开发等领域有广泛应用。
1157

被折叠的 条评论
为什么被折叠?



