Home >Backend Development >Python Tutorial >How to generate random password in python

How to generate random password in python

王林
王林Original
2020-05-11 14:14:064826browse

How to generate random password in python

First introduce the string library and random library (library that generates random numbers), then introduce uppercase and lowercase letters and numbers through string.ascii_letters and string.ascii_digits, and finally use the sample of the random library () returns k random elements.

The specific code is as follows:

import random
import string
a=string.ascii_letters+string.digits
key=[]
def getKey():
	key=random.sample(a,8)
	keys="".join(key)
	return key
for i in range(1000):
	print(getKey())

Recommended tutorial: python tutorial

The above is the detailed content of How to generate random password in python. For more information, please follow other related articles on the PHP Chinese website!

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