产生的账号是以@163.com结尾,长度由用户输入,产生多少条也由用户输入,用户名不能重复,用户名必须由大写字母、小写字母、数字组成,结果如下图:
import string, random mail_list = [] def Mail(): count = int(input('请输入生成邮箱的个数:')) for i in range(count): src1 = random.sample(string.ascii_lowercase, 3) src2 = random.sample(string.ascii_uppercase, 3) src3 = random.sample(string.digits, 2) mail = ''.join(src1)+''.join(src2)+''.join(src3)+'@163.com' if mail not in mail_list: mail_list.append(mail) return mail_list mails = Mail() for mail in mails: fw = open('mail.txt', 'a') fw.write(mail+'\n')