Generate a password in Python
Python tip:
To generate a random password you can use the
secrets
module.For example, you can generate a random password of length 21 containing letters, numbers, and special characters👇
import secrets import string alphabet = string.ascii_letters + string.digits + '!"#$%&/()=?*+|@{}[]' password = "".join(secrets.choice(alphabet) for i in range(21)) print(password) # => *cgsV!2LN|8f7)EzVR]eX