#!/usr/bin/env python # -*- coding: UTF-8 -*- import random #生成随机6位随机数含字母 code = [] for i in range(6): if i == random.randint(1,5): code.append(str(random.randint(1,5))) else: code.append(chr(random.randint(65,90))) print ''.join(code) #转换成字符串
结果
GQW4AZ