本文实例讲述了Python简单生成8位随机密码的方法。分享给大家供大家参考,具体如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import string
#第一种方法
seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-"
sa = []
for i in range(8):
sa.append(random.choice(seed))
salt = ''.join(sa)
print salt
#第二种方法
salt = ''.join(random.sample(string.ascii_letters + string.digits, 8))
print salt
[b]PS:这里再为大家提供两款相关在线工具供大家参考使用:[/b]
[b]在线随机数字/字符串生成工具:
[/b][url=http://tools.jb51.net/aideddesign/suijishu]http://tools.jb51.net/aideddesign/suijishu[/url]
[b]高强度密码生成器:
[/b][url=http://tools.jb51.net/password/CreateStrongPassword]http://tools.jb51.net/password/CreateStrongPassword[/url]
更多关于Python相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/663.htm]Python数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/648.htm]Python Socket编程技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/642.htm]Python函数使用技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/636.htm]Python字符串操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/520.htm]Python入门与进阶经典教程[/url]》及《[url=http://www.1sucai.cn/Special/516.htm]Python文件与目录操作技巧汇总[/url]》
希望本文所述对大家Python程序设计有所帮助。