String Composition Verification with isOOO() Methods
Functions with names in the form of isOOO()
like isalnum()
, isalpha()
, and isdigit()
are used to verify the composition of a string.
These functions check if the characters in a string satisfy certain conditions and return True
or False
accordingly.
The main functions include:
-
isalnum()
: Checks if the string contains only alphabetic characters (A, a, B, b...) and digits (1, 0, 9...) -
isalpha()
: Checks if the string consists solely of alphabetic characters -
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 for validating user input or cleaning data.
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.")
Mission
0 / 1
What is the function to check if a string contains only alphabetic characters?
The function to check if a string contains only alphabetic characters is .
isalnum()
isalpha()
isidentifier()
isdigit()
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result