Home >Backend Development >Python Tutorial >Python生成随机密码

Python生成随机密码

WBOY
WBOYOriginal
2016-06-10 15:17:301160browse

本人  python新手,使用的环境是python2.7,勿喷

复制代码 代码如下:

# -*- coding:utf8 -*-
import random
import string
import sys
reload(sys)
sys.setdefaultencoding("utf8")
def random_number():
    pwnumber=input("请输入需要密码个数:")
    pwlength=input("请输入需要密码长度:")
    if  pwlength         for i in range(pwnumber):
            number=string.join(random.sample(string.digits+string.letters,pwlength)).replace(' ','')
            print number
    else :
        print "目前只支持10位以下密码,请重试!!"
        random_number()
if __name__=="__main__":
    random_number()

以上就是本文的全部内容了,希望对大家学习python能够有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn