美文网首页Python中文社区python面试题集锦python热爱者
python 如何一次随机取出多条数据(能重复/不能重复)

python 如何一次随机取出多条数据(能重复/不能重复)

作者: 零_WYF | 来源:发表于2018-04-12 11:59 被阅读48次

取出的数据可以重复

need=[random.randint(0,100) for _ in range(要取出的数据条数)]

# 随机抽取3个测试题
exam_choice_list = [random.choice(exam_msg_list) for _ in range(3)]
image.png

取出的数据不能重复

need = random.sample([要取数据的列表], 要取出的数据个数)

exam_choice_list = random.sample(exam_msg_list, 3)
image.png

相关文章

网友评论

    本文标题:python 如何一次随机取出多条数据(能重复/不能重复)

    本文链接:https://www.haomeiwen.com/subject/yfsxkftx.html