标签:字符 family pre str 方法 mic range 生成 整数
#coding=utf-8
方法一
import random
checkcode=‘‘
for i in range(4): #0,1,2,3
current=random.randrange(0,4)
if current !=i:
temp=chr(random.randint(65,90)) #65以上是字母,chr()把整数作为参数,返回一个对应的字符
else:
temp=random.randint(0,9)
checkcode +=str(temp)
print checkcode
方法二
import random
checkcode=[]
for i in range(4):
if i==random.randint(1,3):
checkcode.append(str(i))
else:
temp=chr(random.randint(65,90))
checkcode.append(str(temp))
print checkcode
print ‘‘.join(checkcode)
标签:字符 family pre str 方法 mic range 生成 整数
原文地址:https://www.cnblogs.com/hyy0927/p/8893260.html