The choice()
function in the random module is used to randomly select an item from a sequence such as a list, tuple, string, range e.t.c.
choice(seq)
copy
seq | Required. The sequence containing the elements to choose from. |
The function randomly picks an element from the sequence
and returns it. Please note that sets and dictionaries are not sequences since the items are unordered, they, therefore, cannot be used as arguments to the choice()
function, doing so will raise a TypeError
.