python怎么产生5个随机数字?
发布时间:2026-02-03 21:54:50

python生成5个随机数的方法:
1、在循环中使用random.randint()方法生成5个随机数
importrandom count=0 while(count<5): print(random.randint(0,9)) count=count+1
输出结果如下:
94738
random.randint:
语法:
random.randint(a,b)
函数返回数字 N ,N 为 a 到 b 之间的数字(a <= N <= b),包含 a 和 b。
请关注Python自学网了解更多Python知识。
下一篇 Python中猴子补丁是什么?
