You need to write some pycoe

Li Yang * 3

python_hui(18568089292F) 09:40:53
li = [1,2,3,4,5]

import random

# 随机从列表中取出2个
res_li = random.sample(li,2)
print(res_li)
print("-"*9)


# 随机取出一个 random.choice
for i in range(2):
    res_one = random.choice(li)
    li.remove(res_one)
    print(res_one)

print("-"*9)

# 使用randint来实现
for i in range(2):
    ct_li = len(li)  # 4
    idx = random.randint(0,ct_li-1)
    dt = li[idx]
    li.remove(dt)
    print(dt)



python_hui(18568089292F) 09:40:57
文炀*3

Guess you like

Origin blog.csdn.net/ifubing/article/details/94427429