Different ways to select random element from list in Python

Following are the different ways of selecting a random element from a list:



random.randrange()
random.random()
random.choice()
random.randint()

1. random.randrange() :

using this method we can return a random element from the given list.This method generates random value in the specified range.so for lists we need to specify the range as " random.randrange(len(listname)) ".And we will pass the value returned by the above method into our list to genereate the random elementfrom the list....

 •  0 comments  •  flag
Share on Twitter
Published on November 01, 2020 21:57
No comments have been added yet.