生成固定位数含大小写字母符号的密码

Posted testerren

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生成固定位数含大小写字母符号的密码相关的知识,希望对你有一定的参考价值。

使用string包里面的内置函数

>>> import string
>>> dir(string)
[‘Formatter‘, ‘Template‘, ‘_ChainMap‘, ‘_TemplateMetaclass‘, ‘__all__‘, ‘__
ins__‘, ‘__cached__‘, ‘__doc__‘, ‘__file__‘, ‘__loader__‘, ‘__name__‘, ‘__p
e__‘, ‘__spec__‘, ‘_re‘, ‘_string‘, ‘ascii_letters‘, ‘ascii_lowercase‘, ‘as
ppercase‘, ‘capwords‘, ‘digits‘, ‘hexdigits‘, ‘octdigits‘, ‘printable‘, ‘pu
tion‘, ‘whitespace‘]

import random,string
password=""
s=string.digits+string.printable+string.ascii_letters #生成包含大小写字母、符号的字符串
for i in range(9):     #生成长度为9的密码
    password+=random.choice(s)    #使用random的内置函数choice
print(password)

不到十行代码搞定!







以上是关于生成固定位数含大小写字母符号的密码的主要内容,如果未能解决你的问题,请参考以下文章

注册填写密码,最小长度为6个字符是啥

excel怎么随机产生10位混合密码(含数字、字母)?

密码由 6-16 位数字、字母或符号组成,至少包含 2 种字符。 保存

java怎么实现自动生成一个由英文字母(区分大小写)、数字、符号组成,6-12个字符 的密码

生成随机密码

求密码是由6-18位字母和数字的混合组成的正则表达式的js代码,谢谢各位大神!!