Python学习-------random模块(随机验证码)

import random
def v_code():
    code = ''
    for i in range(5):
        # if i == random.randint(0,5):
        #     add = random.randrange(10)
        # else:
        #     add = chr(random.randint(65,91))
        add =random.choice([random.randrange(10),chr(random.randint(65,91))])
        code += str(add)
    return code

a = v_code()
print(a)
原文地址:https://www.cnblogs.com/yujin123456/p/9690424.html