InterviewSolution
Saved Bookmarks
| 1. |
Can you easily check if all characters in the given string is alphanumeric? |
|
Answer» This can be easily done by making use of the isalnum() method that returns TRUE in case the STRING has only alphanumeric characters. For Example - "abdc1321".isalnum() #Output: True"xyz@123$".isalnum() #Output: FALSEAnother way is to use match() method from the re (regex) module as shown: IMPORT reprint(BOOL(re.match('[A-Za-z0-9]+$','abdc1321'))) # Output: Trueprint(bool(re.match('[A-Za-z0-9]+$','xyz@123$'))) # Output: False |
|