python 之 random.sample() 报ValueError: Sample larger than population or is negative

2023-02-18,,,,

def device_id():
device = ''.join(random.sample(string.digits, 19))
return device print(device_id())

执行以上代码时报错,报错内容:

问题分析:random.sample(list, num): 多个字符中生成指定数量的随机list,random.sample(),有两个参数,一个为被选取字符串list,一个为选取的长度num,选择的长度num 必须<= len(list)

python 之 random.sample() 报ValueError: Sample larger than population or is negative的相关教程结束。

《python 之 random.sample() 报ValueError: Sample larger than population or is negative.doc》

下载本文的Word格式文档,以方便收藏与打印。