Site icon Machine Learning Projects

Python Program to Randomly Select an Element From the List – 2023

Machine Learning Projects

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

Example 2: Using the secrets module

import secrets

my_list = ['machine', 'learning', 'projects', 1, 2, 3]
print(secrets.choice(my_list))

Output

2

Check out our other python programming examples

Exit mobile version