随机选择一个元素
foo = ['a', 'b', 'c', 'd', 'e'] from random import choice print choice(foo)
随机选择多个元素
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] slice = random.sample(list, 5) print slice
随机选择一个元素
foo = ['a', 'b', 'c', 'd', 'e'] from random import choice print choice(foo)
随机选择多个元素
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] slice = random.sample(list, 5) print slice