小编Gan*_*h M的帖子

random.choices() 和 random.sample() 函数之间有什么区别?

我有以下列表:list = [1,1,2,2].

应用sample方法 ( rd.sample(list, 3)) 后,输出为[1, 1, 2]

应用choices方法(rd.choices(list, 3))后,输出为:[2, 1, 2]

这两种方法有什么区别?什么时候应该优先选择一个?

python random python-3.x

20
推荐指数
2
解决办法
7359
查看次数

标签 统计

python ×1

python-3.x ×1

random ×1