C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tests: We have 7 strings in our tests list. Some have spaces, punctuation, and one is an empty string.
StringsResult: The only strings that cause isalnum to return true are the ones with no whitespace or punctuation (and at least 1 character).
Python program that uses isalnum method
tests = []
tests.append("The Dev Codes")
tests.append("DotNetPerls")
tests.append("Dot_Net_Perls")
tests.append("Dot0123")
tests.append("dotnetCodex")
tests.append("123")
tests.append("")
for test in tests:
# Test each string for alphanumeric status with isalnum.
if test.isalnum():
print("isalnum: [", test, "]")
else:
print("false: [", test, "]")
Output
false: [ The Dev Codes ]
isalnum: [ DotNetPerls ]
false: [ Dot_Net_Perls ]
isalnum: [ Dot0123 ]
isalnum: [ dotnetCodex ]
isalnum: [ 123 ]
false: [ ]