当前位置: 移动技术网 > IT编程>脚本编程>Python > 生成固定位数含大小写字母符号的密码

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

2019年01月30日  | 移动技术网IT编程  | 我要评论

危城 电影下载,小池彰,戴泽兮

使用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)

不到十行代码搞定!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网