rank vote view answer url
62 1363 1038536 14 url

在列表中随机取一个元素

例如我有如下列表:

foo = ['a', 'b', 'c', 'd', 'e']

从列表中随机取一个元素最好的方法是什么?


import random

foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))
Copyright © taizilongxu 2018 all right reserved,powered by Gitbook该文件修订时间: 2018-10-17 17:33:54

results matching ""

    No results matching ""