Home >Backend Development >Python Tutorial >Python3实现生成随机密码的方法

Python3实现生成随机密码的方法

WBOY
WBOYOriginal
2016-06-16 08:42:351335browse

本文实例讲述了Python3实现生成随机密码的方法,在Python程序设计中有着广泛的实用价值。具体方法如下:

本文实例主要实现创建8位随机密码(大小写字母+数字),采用Python3生成了初级算法的随机密码。

主要功能代码如下:

__author__ = 'Goopand'

import string
import random

def genPassword(length=8,chars=string.digits+string.ascii_letters):
  return ''.join(random.sample(chars*10,8))

if __name__=="__main__":
  for i in range(10):
    print(genPassword(8))

希望本文所述实例对大家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