Python学习笔记_生成验证码
import random def verification_code(): num = [str(x) for x in range(10)] # 列表生成器0-9 upper = [chr(x) for x in range(65,91)] # A-Z lower = [chr(x) for x in range(97,123)] # a-z lst = num + upper + lower # 合并列表 myslice = random.sample(lst,6) # 从列表中随机选取6个元素,作为一个列表返回 ver_code = "".join(myslice) print(ver_code) return ver_code