create a password with uppercase, lowercase letters, numbers and symbols in python

You can create a strong password with all of the above-mentioned characters in Python using the random library along with string library.

Here's how you can do it:

main.py
import random
import string

# Define the length of the password
length = 12

# Define the character set to use when generating the password
lower = string.ascii_lowercase
upper = string.ascii_uppercase
nums = string.digits
symbols = string.punctuation

# Combine the character sets into a single variable
all_characters = lower + upper + nums + symbols

# Use random.choice() to generate a password with the desired length
password = ''.join(random.choice(all_characters) for i in range(length))

# Print the password
print(password)
535 chars
21 lines

This code will generate a random password with a length of 12 characters including uppercase letters, lowercase letters, numbers, and symbols. By varying the length value, you can generate passwords of any desired length.

Make sure to use strong passwords like this to protect your online identity and data.

gistlibby LogSnag