choice() is an inbuilt function in Python programming language that returns a random item from a list, tuple, or string.
random.choice(sequence) Parameters: sequence is a mandatory parameter that can be a list, tuple, or string. Returns: The choice() returns a random item.
Note:We have to import random to use choice() method.
Below is the Python3 implementation of the above approach:
The output every-time will be different as the system returns a random item.
Print any random number 5 times from a given list.
The output changes every time as choice() function is used.
1 4 1 5 7
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.