python教程系列(三.2.7、random模块)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cui130/article/details/86325950

在这里插入图片描述

import random

print(random.random())#(0,1)----float    大于0且小于1之间的小数
 
print(random.randint(1,3))  #[1,3]    大于等于1且小于等于3之间的整数

print(random.randrange(1,3)) #[1,3)    大于等于1且小于3之间的整数
  
print(random.choice([1,'23',[4,5]]))#1或者23或者[4,5]

print(random.sample([1,'23',[4,5]],2))#列表元素任意2个组合

print(random.uniform(1,3))#大于1小于3的小数,如1.927109612082716 

 
item=[1,3,5,7,9]
random.shuffle(item) #打乱item的顺序,相当于"洗牌"
print(item)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/cui130/article/details/86325950