python如何随机选取n个不同的数字

python随机选取n个不同的数字的方法:
1、使用“import random”导入random包

2、通过for语句循环执行n次“random.randint()”语句获取n个随机数并将随机数输入到列表中
n=10示例如下:

3、用set函数去重就可以了

完整代码:

更多Python知识,请关注:云海天python教程网!!
来源:PY学习网:原文地址:https://www.py.cn/article.html

python随机选取n个不同的数字的方法:
1、使用“import random”导入random包

2、通过for语句循环执行n次“random.randint()”语句获取n个随机数并将随机数输入到列表中
n=10示例如下:

3、用set函数去重就可以了

完整代码:

更多Python知识,请关注:云海天python教程网!!
来源:PY学习网:原文地址:https://www.py.cn/article.html