Home >>Python Random Module >Python Random sample() Method
Python Random sample() Method is an inbuilt function in python which is used to return a particular list of items chosen from a sequence (like string, list, tuple).
Syntax:random.sample(sequence, k)
Parameter | Description |
---|---|
sequence | It is Required a sequence of items. |
k | It Required the returned list size. |
import random
mygame = ["football", "cricket", "vollyball"]
print(random.sample(mygame, k=2))
import random
mygame = ["football", "cricket", "vollyball"]
print(random.sample(mygame, k=1))