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.")
Mission
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

Code Editor

Run
Generate

Execution Result