python 验证码

来源:互联网 发布:oppo软件开放平台 编辑:程序博客网 时间:2024/06/03 18:38

使用random模块,结合列表操作,可以生成验证码,如下:

#验证码import randomcode=[]#print ord('A'),ord('Z')for i in range(6): #[0,1,2,3,4,5]    j=random.randint(0,99)    if j%2==0:        temp1=random.randint(0,9)        code.append(str(temp1))    else:        temp2=random.randint(65,90)        code.append(chr(temp2))        #print codeprint ''.join(code)


友情链接:Python random模块



1 0
原创粉丝点击