Skip to content
Advertisement

Picking a Random Word from a list in python?

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
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement