In [1]:
import random

In [2]:
l = [0, 1, 2, 3, 4]

In [3]:
print(random.sample(l, 3))


[2, 4, 0]

In [4]:
print(type(random.sample(l, 3)))


<class 'list'>

In [5]:
print(random.sample(l, 1))


[3]

In [6]:
print(random.sample(l, 0))


[]

In [7]:
# print(random.sample(l, 10))
# ValueError: Sample larger than population or is negative

In [8]:
print(random.sample(('xxx', 'yyy', 'zzz'), 2))


['xxx', 'yyy']

In [9]:
print(random.sample('abcde', 2))


['b', 'e']

In [10]:
print(tuple(random.sample(('xxx', 'yyy', 'zzz'), 2)))


('xxx', 'yyy')

In [11]:
print(''.join(random.sample('abcde', 2)))


dc

In [12]:
l_dup = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]

In [13]:
print(random.sample(l_dup, 3))


[3, 1, 1]

In [14]:
print(set(l_dup))


{0, 1, 2, 3}

In [15]:
print(random.sample(set(l_dup), 3))


[1, 3, 2]