Write a Python Program to Randomly Select an Element From the List

Python Program to Randomly Select an Element From the List

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

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

Write a Python Program to Randomly Select an Element From the List

PROGRAM: Python Program to Randomly Select an Element From the List

/* Python Program to Randomly Select an Element From the List */

1: Using random module

import random

my_list = [1, ‘a’, 32, ‘c’, ‘d’, 31]
print(random.choice(my_list))

OUTPUT:-

31

2: Using secrets module

import secrets

my_list = [1, ‘a’, 32, ‘c’, ‘d’, 31]
print(secrets.choice(my_list))

OUTPUT:-c

Leave a Reply

Your email address will not be published. Required fields are marked *