前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >生成固定位数含大小写字母符号的密码

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

作者头像
py3study
发布2020-01-17 12:43:13
6220
发布2020-01-17 12:43:13
举报
文章被收录于专栏:python3python3

使用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']

代码语言:javascript
复制
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)

不到十行代码搞定!

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-05-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用string包里面的内置函数
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档