Validate a Username
Beginner · Write the code · from Every Python String Method Explained with Examples
From the lesson: Every Python String Method Explained with Examples
Strings in Python come with a toolbox of built-in methods. These methods let you change case, remove extra spaces, search for words, split text apart, and much more.
Read the lessonWrite a program that validates a username based on these rules:
Three usernames are provided. For each one, print "Valid" if it passes both rules, or "Invalid" if it fails either rule.
Expected output:
player42: Valid
ab: Invalid
hello world!: Invalidusernames = ["player42", "ab", "hello world!"]
# Check each username and print if it's valid or invalid
More string methods exercises
- Clean Up User InputBeginner
- Count Word OccurrencesBeginner
- Replace All OccurrencesBeginner
- Split a CSV LineBeginner
- Fix the Bug -- find() vs index()Beginner
All Python exercises · 50 practice problems · Python Fundamentals quiz