我有以下列表:list = [1,1,2,2].
list = [1,1,2,2]
应用sample方法 ( rd.sample(list, 3)) 后,输出为[1, 1, 2]。
sample
rd.sample(list, 3)
[1, 1, 2]
应用choices方法(rd.choices(list, 3))后,输出为:[2, 1, 2]。
choices
rd.choices(list, 3)
[2, 1, 2]
这两种方法有什么区别?什么时候应该优先选择一个?
python random python-3.x
python ×1
python-3.x ×1
random ×1