0
0
Pythonprogramming~5 mins

String validation checks in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the str.isalpha() method check in a string?
It checks if all characters in the string are letters (a-z or A-Z) and the string is not empty.
Click to reveal answer
intermediate
How does str.isdigit() differ from str.isnumeric()?
str.isdigit() checks if all characters are digits (0-9), while str.isnumeric() also returns True for numeric characters like fractions or superscripts.
Click to reveal answer
beginner
What does str.isspace() check for in a string?
It returns True if the string contains only whitespace characters like spaces, tabs, or newlines, and is not empty.
Click to reveal answer
beginner
Explain the use of str.isalnum().
It checks if all characters in the string are letters or numbers (no spaces or symbols) and the string is not empty.
Click to reveal answer
beginner
What will 'Hello123'.isalpha() return and why?
It will return False because the string contains numbers along with letters, and isalpha() requires only letters.
Click to reveal answer
Which method checks if a string contains only letters and is not empty?
Aisalpha()
Bisdigit()
Cisspace()
Disalnum()
What does str.isdigit() return for the string '12345'?
ATrue
BFalse
CError
DDepends on Python version
Which method would return True for a string containing only spaces and tabs?
Aisalnum()
Bisnumeric()
Cisalpha()
Disspace()
What will 'abc123'.isalnum() return?
AError
BTrue
CFalse
DNone
Which method is best to check if a string contains only numeric characters including fractions or superscripts?
Aisalpha()
Bisdigit()
Cisnumeric()
Disspace()
Describe how you can check if a string contains only letters or numbers in Python.
Think about a method that allows both letters and digits but no spaces.
You got /4 concepts.
    Explain the difference between isdigit() and isnumeric() methods.
    Consider what kinds of numeric characters each method accepts.
    You got /4 concepts.