How to Choose a Random Word from a List in Python?

Estimated read time 1 min read

You can use the random.choice() function in Python to choose a random word from a list of words. Here’s an example code snippet:

import random

my_words = ["apple", "banana", "cherry", "date", "elderberry"]
random_word = random.choice(my_words)

print(random_word)

In this example, the random.choice() function is used to choose a random word from the my_words list. The output will be a single random word from the list.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply