Hey guys, in this blog we will see a Python Program to Randomly Select an Element From the List.
Example 1: Using random module
import random my_list = ['machine', 'learning', 'projects', 1, 2, 3] print(random.choice(my_list))
Output
projects
- random.choice() is used to choose an element at random from the provided list.
Example 2: Using the secrets module
import secrets my_list = ['machine', 'learning', 'projects', 1, 2, 3] print(secrets.choice(my_list))
Output
2
- secrets.choice() is used to choose an element at random from the provided list.
Check out our other python programming examples…