random库choice、choices和sample区别

import string
import random

# 返回一个
print(random.choice(list(string.digits)))
# 返回一个列表,列表元素不重复
print(''.join(random.sample(list(string.digits), 5)))
# 返回一个列表,列表元素可能重复
print(''.join(random.choices(list(string.digits), k=5)))

9
05871
87974

 

posted @ 2023-07-28 15:58  你说夕阳很美  阅读(148)  评论(0)    收藏  举报