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?
✗ Incorrect
isalpha() returns True only if all characters are letters and the string is not empty.What does
str.isdigit() return for the string '12345'?✗ Incorrect
Since '12345' contains only digits,
isdigit() returns True.Which method would return True for a string containing only spaces and tabs?
✗ Incorrect
isspace() returns True if the string contains only whitespace characters.What will
'abc123'.isalnum() return?✗ Incorrect
isalnum() returns True if all characters are letters or numbers, which is true here.Which method is best to check if a string contains only numeric characters including fractions or superscripts?
✗ Incorrect
isnumeric() covers a wider range of numeric characters than isdigit().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.