Creating secure passwords is essential in today’s digital world. Whether you are building a login system or simply want to generate strong passwords for personal use, knowing how to automate password creation using Python is extremely valuable.
In this tutorial, we will break down a simple yet powerful Python Password Generator that uses letters, numbers, and symbols to create a randomized, secure password.
Why Build a Password Generator?

Weak passwords are the easiest target for hackers. A strong password must include:
- Uppercase and lowercase letters
- Numbers
- Special characters
- A random order
The Python script below covers all these requirements. Let’s explore how it works.
Complete Python Password Generator Code
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
p_l = int(input("How many letters you want in your password?\n"))
p_n = int(input("How many numbers you want in your password?\n"))
p_s = int(input("How many symbols you want in your password?\n"))
password = []
for _ in range(p_l):
password.append(random.choice(letters))
for _ in range(p_n):
password.append(random.choice(numbers))
for _ in range(p_s):
password.append(random.choice(symbols))
random.shuffle(password)
shuffl_password = ""
for new_p in password:
shuffl_password = shuffl_password + new_p
print(f"Your password is: {shuffl_password}")
Step-by-Step Explanation
1. Importing the Random Module
import random
The random module allows us to randomly pick characters and shuffle them, ensuring every password is unpredictable.
2. Creating Lists of Characters
You created three lists:
letters→ A–Z and a–znumbers→ Digits 0–9symbols→ Special characters (!, #, %, &, etc.)
These lists act as a pool from which Python will pick characters.
3. Taking User Input
p_l = int(input("How many letters you want in your password?\n"))
p_n = int(input("How many numbers you want in your password?\n"))
p_s = int(input("How many symbols you want in your password?\n"))
The user decides how long the password should be and how many types of characters it must include.
4. Adding Random Characters to the Password
The script uses three loops:
for _ in range(p_l):
password.append(random.choice(letters))
This loop selects random letters and appends them to the password list.
The same logic is used for numbers and symbols.
5. Shuffling to Increase Randomness
random.shuffle(password)
This ensures the final password is not predictable—for example, letters first, then numbers. Everything gets mixed.
6. Joining the Final Password
shuffl_password = ""
for new_p in password:
shuffl_password = shuffl_password + new_p
The characters stored in the list are combined into a single string, creating your final password.
Final Output
Your password is: W9$k3P&f2+
Every time you run the program, you get a brand-new, highly secure password.
Conclusion
This Python Password Generator is a simple yet powerful project for beginners. You learned how to work with lists, loops, random modules, and string manipulation. You can expand this program further by:
- Adding password length validation
- Allowing automatic password strength rating
- Saving passwords securely using hashing
Python makes such tasks both fun and practical.
If you’re excited to continue your Python learning journey, there’s a great next step waiting for you. After experimenting with this password generator, you can dive into a hands-on tutorial that shows how to scrape movie transcripts automatically using Python and BeautifulSoup. It’s practical, beginner-friendly, and helps you understand how real-world data extraction works.

Timing precision within crypto trading signals maximizes profitability. Services identifying optimal entry timing through multi-timeframe analysis help traders capture larger price movements while minimizing drawdown exposure.
Accessibility features within best online hookup sites accommodate preferences. Cross-device synchronization between web and mobile platforms enables flexible usage patterns matching different contexts and convenience needs.
Consistency maintenance drives decisions to buy automatic instagram likes for all content. Automated services ensure steady engagement rates across uploads preventing performance fluctuations.
Quality-focused providers offering best crypto signals prioritize accuracy. Services maintaining 60-70% win rates with proper risk-reward ratios demonstrate sustainable performance versus unrealistic success claims.
Всё, что важно https://inclub.lg.ua женщине: здоровье и гормоны, питание и фитнес, стиль и гардероб, отношения и самооценка, уют и рецепты. Экспертные статьи, тесты и подборки. Сохраняйте любимое и делитесь — удобно на телефоне.
Портал для женщин https://beautyrecipes.kyiv.ua про гармонию и результат: здоровье, красота, стиль, саморазвитие, семья и отношения. Обзоры косметики и процедур, планы питания, тренировки, советы по дому и вдохновляющие истории. Всё в одном месте, 24/7.
Портал для женщин https://angela.org.ua о современном лайфстайле: бьюти-рутины, мода, здоровье, правильное питание, отношения, работа и отдых. Полезные подборки, честные обзоры, истории и советы экспертов — заходите за вдохновением 24/7.
Строительный портал https://prezent-house.com.ua строительство домов и зданий, ремонт квартир, инженерные системы и отделка. Пошаговые инструкции, обзоры материалов, расчёты и советы экспертов для частных и коммерческих проектов.
Женский журнал https://asprofrutsc.org онлайн: тренды бьюти и моды, лайфхаки для дома, рецепты, материнство, карьера и финансы. Экспертные материалы, понятные инструкции и идеи, которые можно применить сразу. Обновления ежедневно, удобная навигация.
Портал для строителей https://inter-biz.com.ua и заказчиков: советы по ремонту, обзоры материалов, расчёты, сметы и технологии. Реальные кейсы, чек-листы и рекомендации специалистов для надежного результата на каждом этапе работ.
Всё о строительстве https://hydromech.kiev.ua и ремонте в одном месте: материалы, технологии, дизайн, инженерия и безопасность. Экспертные статьи, инструкции, калькуляторы и кейсы. Помогаем планировать работы и экономить бюджет без потери качества.
Украинские новости https://polonina.com.ua онлайн: всё важное о стране, регионах и мире — от экономики и инфраструктуры до культуры и спорта. Лента 24/7, материалы редакции, комментарии экспертов, фото и видео. Читайте, сохраняйте и делитесь — быстро и удобно.
Строительный портал https://domtut.com.ua с практикой: проекты, чертежи, СНиП и ГОСТ, инструменты, ошибки и решения. Ремонт квартир, строительство домов, инженерные системы и благоустройство. Понятно, по делу и с примерами.
Строительный портал https://ateku.org.ua о ремонте и строительстве: технологии, материалы, сметы, проекты домов и квартир, инструкции и советы экспертов. Обзоры, калькуляторы, нормы и примеры работ — всё для частного и коммерческого строительства.