Random

  

生成随机验证码

 #字母跟数字的组合

import random
checkcode=''   #字符串为空
for i in range(4):
    current=random.randrange(0,4)
    if current==i:
        tmp=chr(random.randint(65,90))  #chr()将数字转换成字母
    else:
        tmp=random.randint(0,9)

    checkcode+=str(tmp)
print(checkcode)
原文地址:https://www.cnblogs.com/nodchen/p/8338052.html