标签:color 输出 turn 多个 int sam 验证 浮点 shuffle
1 import random 2 3 print(random.random()) #随机输出0-1的浮点数 4 print(random.randint(0,10)) #[0,10]随机输出一个整数,包括0和10 5 print(random.randrange(0,10)) #[0,10)随机输出一个整数,包括0不包括10 6 print(random.choice([1,2,3,5,4,6,9])) #随机选取列表中顾的一个值 7 print(random.sample([1,2,3,5,4,6,9],3)) #随机选取列表中的多个元素 8 print(random.uniform(1,10)) #随机输出1,10的浮点数 9 10 l = [1,2,3,4,5,6,7,8,9] 11 random.shuffle(l) #打乱顺序 12 print(l) 13 14 ##验证码 15 import random 16 def v_code(): 17 ret = ‘‘ 18 for i in range(4): 19 num = random.randint(0,9) 20 zimu = chr(random.randint(65,90)) 21 choices = random.choice([num,zimu]) 22 ret += str(choices) 23 return ret 24 25 print(v_code())
标签:color 输出 turn 多个 int sam 验证 浮点 shuffle
原文地址:https://www.cnblogs.com/humanskin/p/8920462.html