随机生成验证码
# import random # print(random.random()) #0-1的小数 # print(random.randint(1,3)) #包括1和3 # print("--",random.randrange(1,3)) #不包括1和3 #随机生成四位验证码 import random checkcode = '' for i in range(4): current = random.randrange(0,4) if current != i: temp = chr(random.randint(65,90)) else: temp = random.randint(0,9) checkcode += str(temp) print(checkcode) #KS3G #随机生成8位验证码 import string print(string.ascii_lowercase) #abcdefghijklmnopqrstuvwxyz print(string.digits) #0123456789 obj = random.sample(string.ascii_lowercase+string.digits,8) print(obj) #['i', 'm', 'o', '9', '6', 'p', 'g', '0'] row = "".join(random.sample(string.ascii_lowercase+string.digits,8)) print(row) #417x6kyt