Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




isalnum( ) FUNCTION


isalnum( ) Function


The isalnum() Function is used to check if all the letters in the String are alphanumeric or not.


i.e. Alphanumeric String actually means, the String should only consist of numbers (0 to 9) or alphabets (A to Z or a to z). Any values other than that will not be considered.


Example :


x = "29B"
if x.isalnum():
    print("All the letters in the String are alphanumeric")
else:
    print("No! Not all the letters in the String are alphanumeric")


Output :



  All the letters in the String are alphanumeric

In the above code, we have declared a String '29B' that has alphanumeric characters only.


x = "29B"

java_Collections

So, to check, if all the letters in the String are alphanumeric, we have used 'isalnum( )' function.


if x.isalnum():
    print("All the letters in the String are alphanumeric")
else:
    print("No! Not all the letters in the String are alphanumeric")

And in this case, all the letters in the String are alphanumeric. So, we got the below output.


All the letters in the String are alphanumeric

Similarly, let us look at the next example.


Example :


x = "29 B"
if x.isalnum():
    print("All the letters in the String are alphanumeric")
else:
    print("No! Not all the letters in the String are alphanumeric")


Output :



  No! Not all the letters in the String are alphanumeric

In the above code, we have declared a String '29 B' that has a space other than alphanumeric characters.


x = "29 B"

java_Collections

So, to check, if all the letters in the String are alphanumeric, we have used 'isalnum( )' function.


if x.isalnum():
    print("All the letters in the String are alphanumeric")
else:
    print("No! Not all the letters in the String are alphanumeric")

And in this case, all the letters in the String are not alphanumeric. So, we got the below output.


No! Not all the letters in the String are alphanumeric