python random模块的几个函数

1,shuffle:将列表中的元素随机排序

random.shuffle(list) 参数是列表类型。

 

2,choice:随机返回参数的某一项,参数可以是列表,元组或字符串等。

random.choice(arg)

 

3,sample:随机返回一个列表的一个片段。

random.sample(list,4) 随机返回list的4个元素,也是一个列表的形式。

posted @ 2020-11-09 23:33  NEWdun  阅读(160)  评论(0)    收藏  举报