目录

* 一、random模块 <https://www.cnblogs.com/nickchen121/p/10807555.html#一random模块>
一、random模块
import random # 大于0且小于1之间的小数 print(random.random()) 0.42866657593385415 #
大于等于1且小于等于3之间的整数 print(random.randint(1, 3)) 3 # 大于等于1且小于3之间的整数
print(random.randrange(1, 3)) 2 # 大于1小于3的小数,如1.927109612082716
print(random.uniform(1, 3)) 2.1789596280319605 # 列表内的任意一个元素,即1或者‘23’或者[4,5]
print(random.choice([1, '23', [4, 5]])) [4, 5] # random.sample([],
n),列表元素任意n个元素的组合,示例n=2 print(random.sample([1, '23', [4, 5]], 2)) ['23', 1] lis
= [1, 3, 5, 7, 9] # 打乱l的顺序,相当于"洗牌" random.shuffle(lis) print(lis) [9, 1, 5, 7,
3]

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信