Python3: random
2023-06-18 本文已影响0人
LET149
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 之间的随机整数