Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

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 to validate user input or clean 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.")

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.