标签:rand pre += shuf ice and print sam shu
#随机模块 import random ret=random.random()#0-1的随机的浮点数 ret1 = random.randint(1,6) # 1-6的整数,1和3能取 #print ret1 ret2 = random.randrange(1,6)# 1-6的整数,1能取,3不能取 #print ret2 ret3 = random.choice([11,22]) #print ret3 ret4 = random.sample([11,22,33,44],2) #随机两个 #print ret4 #任意范围的浮点型 ret5 = random.uniform(1,4) #print ret5 item = [1,3,5,7,9] ret6 = random.shuffle(item) #打乱顺序 #print ret6 #做个小demo,数字和字母双拼的验证码: def v_code(): retd = "" for i in range(5): num = random.randint(0,9) alf = chr(random.randint(65,122)) #随机取到一个字母 s = str(random.choice([num,alf])) retd+=s return retd print v_code()
标签:rand pre += shuf ice and print sam shu
原文地址:https://www.cnblogs.com/wangyue0925/p/8978766.html