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

How to generate random password in python

王林
Release: 2020-05-11 14:14:06
Original
4830 people have browsed it

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())
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template