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




isalpha( ) FUNCTION


isalpha( ) Function


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


i.e. The String should only consist of alphabets (A to Z or a to z). Any values other than that will not be considered.


Example :


x = "Hello"
if x.isalpha():
    print("All the letters in the String are alphabets")
else:
    print("No! Not all the letters in the String are alphabets")


Output :



  All the letters in the String are alphabets

In the above code, we have declared a String 'Hello' that has alphabets only.


x = "Hello"

java_Collections

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


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

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


All the letters in the String are alphabets

Similarly, let us look at the next example.


Example :


x = "Hello29"
if x.isalpha():
    print("All the letters in the String are alphabets")
else:
    print("No! Not all the letters in the String are alphabets")


Output :



  No! Not all the letters in the String are alphabets

In the above code, we have declared a String 'Hello29' that has numbers other than alphabets.


x = "Hello29"

java_Collections

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


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

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


No! Not all the letters in the String are alphabets