random 随机选取对比sample,choice,choices

from random import sample,choice,choices


# In[2]:


list_1 = [1,2,3,4,5] # 随机选取一个元素


# In[10]:


choice(list_1)


# In[48]:


choices(list_1,k = 4) # 随机选取4个元素,会出现重复


# In[53]:


sample(list_1,k=4)   # 随机选取4个元素,不会出现重复

猜你喜欢

转载自blog.csdn.net/haohaomax1/article/details/111991810
今日推荐