Python randomly generates a password with a specified length.
This example describes how to randomly generate a password of a specified length in python. Share it with you for your reference. The details are as follows:
The following python code randomly combines various characters to generate a random password with a specified length
The string object in python has several common methods to output different characters:
String. ascii_letters
All characters that output the ascii code
String. digits
Output '123 '.
String. punctuation
Punctuation in ascii
Print string. ascii_lettersprint string. digitsprint string. punctuation
The output result is as follows:
AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
! "# $ % & '() * +,-./:; <=>? @ [\] ^ _ '{| }~
The following code is used to generate a random password
Import stringfrom random import * characters = string. ascii_letters + string. punctuation + string. digitspassword = "". join (choice (characters) for x in range (randint (8, 16) print password
I hope this article will help you with Python programming.