标签:str bsp python sam pre process 验证 col ini
random库
1 import random 2 3 print(random.random())# 0-1 4 5 print(random.randint(1,8)) # 1-8 ,包含8 6 7 print(random.choice(‘hello‘)) # 随机选择 8 9 print(random.choice([‘123‘,4,[1,2]])) # 随机选择 10 11 print( random.sample( [‘123‘,4,[1,2]], 2 ) ) #随机选择其中两个值 12 13 print(random.randrange(1,3)) # 值1-2,不包含3,常用 14 15 def v_code(): 16 code = ‘‘ 17 for i in range(5): 18 19 add = random.choice([random.randrange(10),chr( random.randrange(65,91) ) ]) #随机选择数字或字母 20 21 code += str(add) 22 23 print(code) 24 25 v_code() # 5位随机验证码
执行结果:
0.7725728660681052 2 e 123 [‘123‘, [1, 2]] 2 RVXL6 Process finished with exit code 0
标签:str bsp python sam pre process 验证 col ini
原文地址:https://www.cnblogs.com/112358nizhipeng/p/9531782.html