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!