Lecture
String Composition Verification with isOOO() Methods
Functions with names like isalnum(), isalpha(), and isdigit() follow the isXXX() pattern and are used to verify the composition of a string.
These functions check whether the characters in a string meet specific conditions and return True or False accordingly.
The main functions include:
-
isalnum(): Checks if the string contains only alphabetic characters (A–Z, a–z) and digits (0–9), with no spaces or special characters. -
isalpha(): Checks if the string contains only alphabetic characters (A–Z, a–z). -
isdigit(): Checks if all characters in the string are digits (0–9).
Examples using isOOO()
text = "Python3" print(text.isalnum()) # True print(text.isalpha()) # False print(text.isdigit()) # False
When are these functions used?
isOOO() functions are primarily used to validate user input or clean data by checking whether the input matches expected character types.
Example of Input Validation
text = input("Please enter your username containing letters or numbers: ") if text.isalnum(): print("Valid input: The string contains only letters and/or numbers.") else: print("Invalid input: The string contains special characters or spaces.")
Previous lessonRemoving Leading and Trailing Whitespace with the strip() FunctionNext lessonFinding the Position of a Specific Character Using find() and rfind()
Lessons in this chapter · String Formatting Made Easy
- 1. Inserting Variables into Strings with the format() Function
- 2. Tips for Using `format()` Function - indexError
- 3. Displaying Integers with the format() Function
- 4. Handling Floating-Point Numbers with the format() Function
- 5. Multiple-choice quiz
- 6. Case Conversion Methods upper() and lower()
- 7. Removing Leading and Trailing Whitespace with the strip() Function
- 8. String Composition Verification with isOOO() Methods
- 9. Finding the Position of a Specific Character Using find() and rfind()
- 10. Using the split() Method for Strings
- 11. How to Check if a Specific Character Exists in a String
- 12. Multiple-choice quiz
- 13. How to Format Strings with f-Strings
- 14. Comparison of format() Function and f-Strings
- 15. Using the `input` Function to Receive User Input
- 16. Indicating Invalid Values with ValueError
- 17. Coding Quiz - Splitting Strings
- 18. Multiple-choice quiz
- 19. Fill-in-the-blank quiz
Quiz
0 / 1
What function checks if a string contains only alphabetic characters?
The function used to check whether a string contains only alphabetic characters is .
isalnum()
isalpha()
isidentifier()
isdigit()
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help