方法一:
#coding: utf-8
import random
import string
checkcode = 」
for i in range(4):
current = random.randrange(0,6)
if current != i:
temp = chr(random.randint(65,90))
else:
temp = random.randint(0,9)
checkcode += str(temp)
print checkcodegit
方法二web
#coding: utf-8 import random import string zimu = string.ascii_letters shuzi = string.digits str_source = zimu+ shuzi print ''.join(random.sample(str_source,4))