python下random随机选择的三种方式
from random import sample,choice,choices list_1 = [1,2,3,4,5,6] # 从列表随机选取一个元素,整数 ret = choice(list_1) # 3 # 从列表里随机选取多个元素,结果是列表,但是元素会重复 # ret = choices(list_1,k=3) # [6, 3, 3] # 从列表里随机选取多个元素,结果是列表,但是元素不会重复 # ret = sample(list_1,k=3) # [1, 6, 4] print(ret) #