1. 随机选择数字
函数:
choice()
from random import choice
choice([1,2,3,4,5]) 在列表中随机选一个数
2. 生成随机整数
函数:
randint()
from random import randint
randint(1,4) 生成介于 1 和 4 之间的随机整数
函数:
choice()
from random import choice
choice([1,2,3,4,5]) 在列表中随机选一个数
函数:
randint()
from random import randint
randint(1,4) 生成介于 1 和 4 之间的随机整数
本文标题:Python3: random
本文链接:https://www.haomeiwen.com/subject/jopozrtx.html
网友评论