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())
posted on 2019-10-15 14:54  Test-Billy  阅读(373)  评论(0编辑  收藏  举报