This question already has an answer here:
这个问题已经有了答案:
- How to randomly select an item from a list? 12 answers
- 如何从列表中随机选择一个项目?12个答案
The first examples that I googled didn't work. This should be trivial, right?
我用谷歌搜索的第一个例子是无效的。这应该很简单,对吧?
2 个解决方案
#1
133
import random
random.choice (mylist)
#2
27
import random
random.choice([1, 2, 3])
#1
133
import random
random.choice (mylist)
#2
27
import random
random.choice([1, 2, 3])