How do I select a random element from an array in

2019-02-01 16:00发布

问题:

This question already has an answer here:

  • How to randomly select an item from a list? 15 answers

The first examples that I googled didn't work. This should be trivial, right?

回答1:

import random
random.choice (mylist)


回答2:

import random
random.choice([1, 2, 3])