This example describes how Python randomly generates a specified length password. Share to everyone for your reference. Specifically as follows:
The following Python code generates a random password of a specified length by randomly combining various characters
The string object in Python has several common methods for outputting a variety of different characters:
Output all characters of ASCII code
Output ' 0123456789 '.
Punctuation in ASCII
Print string.ascii_letters
print string.digits
print string.punctuation
The output results are as follows:
Abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
0123456789
!" #$%& ' () *+,-./:;<=>?@[\]^_ ' {|} ~
The following code is used to generate random passwords
Import string from
random import *
characters = string.ascii_letters + string.punctuation + string.digits
Password = "". Join (choice (characters) for x in range (Randint (8))
Print password
I hope this article will help you with your Python programming.