方法一:
#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 checkcode方法二
#coding: utf-8import randomimport stringzimu = string.ascii_lettersshuzi = string.digitsstr_source = zimu+ shuziprint ''.join(random.sample(str_source,4))