ratwolf
Bronze Coder
Want to generate a secure, random password in just one line of Python? Here's a quick one-liner using random and string modules:
This creates a random 12-character password with letters (both uppercase and lowercase), digits, and special characters. You can change the k=12 to adjust the length of the password
Python:
import random, string
password = ''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=12))
print(password)
This creates a random 12-character password with letters (both uppercase and lowercase), digits, and special characters. You can change the k=12 to adjust the length of the password
Last edited: