Python String isalnum
Now, we are going to learn about the isalnum method. As the name of the method suggests, with this method, we can check if all the characters in the string are alphanumeric. The method returns True if all the characters in the string are alphanumeric, and False otherwise. Let’s have a look at a simple program, which tries to demonstrate the use of the isalnum method.
Python String isalnum() Method
As you can see in the above program, we have a string, in which, there are alphabets and numbers. Then, we are calling the isalnum method. In this case, the method is going to return True, since all the characters in the given string are alphanumeric. You can try executing the program and observing the output.
Now, Let’s have a look at another example, in which, we would have some symbols as well, Let’s have a look at the program.
As you can see in the above program, we have a string, in which, we have some alphanumeric characters, but there is also a symbol. So, the return value from the isalnum method is going to be False this time. You can try executing the program and checking the output.
So, as and when required, we can make use of the isalnum method, which can be used to check if all the characters in the string are alphanumeric. It returns True if all the characters in the string are alphanumeric, and False otherwise.