In Python 3, how would I print a random word from a list of words?
Advertisement
Answer
Use the random.choice()
function:
JavaScript
x
5
1
>>> import random
2
>>> a = ["Stack", "Overflow", "rocks"]
3
>>> print(random.choice(a))
4
rocks
5
In Python 3, how would I print a random word from a list of words?
Use the random.choice()
function:
>>> import random
>>> a = ["Stack", "Overflow", "rocks"]
>>> print(random.choice(a))
rocks