pythonrandomword-list

Picking a Random Word from a list in python?


In Python 3, how would I print a random word from a list of words?


Solution

  • Use the random.choice() function:

    >>> import random
    >>> a = ["Stack", "Overflow", "rocks"]
    >>> print(random.choice(a))
    rocks