Python——常见模块(四)——random

五、random模块

random.randint(1,5) # 大于1且小于等于5的整数
random.randrange(1,10,2)#大于1且小于等于10的奇数
random.choice([1,'23',[4,5]])#返回1或者23或者[4,5]
random.sample([1,'23',[4,5]],2) #列表元素任意2个组合
#打乱列表顺序
item=[1,3,5,7,9]
random.shuffle(item) #打乱顺序

猜你喜欢

转载自www.cnblogs.com/cxys85/p/9751230.html