In Python 3, how would I print a random word from a list of words?
Advertisement
Answer
Use the random.choice()
function:
>>> import random >>> a = ["Stack", "Overflow", "rocks"] >>> print(random.choice(a)) rocks
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