python学习笔记08:random模块
1 import random 2 number = random.randint(1, 100) #随机整数 3 f = random.uniform(1, 100) #随机小数 4 5 s = '12345' 6 print(random.choice(s)) #从数据里面随机选择一个元素 7 8 l = [1, 3, 5, 7, 9] 9 result = random.sample(l, 3) #随机从list里面取n个元素 10 print(result) 11 12 l2 = [str(i) for i in range(1, 14)] 13 random.shuffle(l2) #洗牌,打乱 14 print(l2)