python -生成随机的验证码

import random
def v_code():
code= ''
for i in range(5):
num = random.randint(0,9) #随机生成0到9的整数
alf = chr(random.randint(65,90)) #根据 ascii码,随机生成字母
add = random.choice([num,alf]) #随机返回 num 或者 alf
code=''.join([code,str(add)]) #join用于将序列中的元素以指定的字符连接生成一个新的字符串

return code
print(v_code())
原文地址:https://www.cnblogs.com/jmc218/p/11677664.html