import random def zd(len,type): s='' if type==1:#只生成数字 for i in range(len): s=s+str(random.randint(0,9)) elif type==2:#只生成字母 for i in range(len): s=s+str(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')) else :#生成数字和字母 for i in range(len): s=s+str(random.choice('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')) return s print(zd(4,2))
生成指定长度字符串,参数为长度,类型
最新推荐文章于 2020-09-14 09:59:12 发布