Challenge - 5 Problems
String Validation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of string isalnum() method
What is the output of this Python code snippet?
Python
s = "Hello123" print(s.isalnum())
Attempts:
2 left
๐ก Hint
isalnum() returns True if all characters are letters or digits and string is not empty.
โ Incorrect
The string "Hello123" contains only letters and digits, so isalnum() returns True.
โ Predict Output
intermediate2:00remaining
Output of string isdigit() with spaces
What will this code print?
Python
s = "123 456" print(s.isdigit())
Attempts:
2 left
๐ก Hint
Spaces are not digits.
โ Incorrect
The string contains a space character, which is not a digit, so isdigit() returns False.
โ Predict Output
advanced2:00remaining
Result of islower() on mixed case string
What does this code output?
Python
s = "helloWorld" print(s.islower())
Attempts:
2 left
๐ก Hint
islower() returns True only if all letters are lowercase and there is at least one letter.
โ Incorrect
The string "helloWorld" has uppercase 'W', so islower() returns False.
โ Predict Output
advanced2:00remaining
Output of isspace() with newline character
What will this code print?
Python
s = "\n" print(s.isspace())
Attempts:
2 left
๐ก Hint
isspace() returns True if all characters are whitespace characters.
โ Incorrect
The newline character is considered whitespace, so isspace() returns True.
โ Predict Output
expert3:00remaining
Output of complex string validation expression
What is the output of this code?
Python
s = "Python3" result = s.isalpha() or s.isalnum() and not s.isdigit() print(result)
Attempts:
2 left
๐ก Hint
Remember operator precedence: 'and' before 'or'.
โ Incorrect
Expression evaluates as s.isalpha() or (s.isalnum() and not s.isdigit()). s.isalpha() is False because of '3'. s.isalnum() is True, s.isdigit() is False, so overall True.