Signup/Sign In
LAST UPDATED: JUNE 4, 2020

Python String isaplha()

Python String isaplha() returns true if a given string consists of alphabets only.

  • String isalpha() is an inbuilt method for string handling.

  • It returns true only if all characters of a string are alphabets(both uppercase and lowercase) only.

  • One thing to note is whitespace is not considered as an alphabet; thus if there is a whitespace in string then this method returns false for that string.

Python String isalpha(): Syntax

Below we have a basic syntax of String isalpha() in Python:

string.isalpha()

Note: In the above syntax string denotes the string variable on which isalpha() method will be applied.

Python String isalpha(): Parameters

From the syntax it is clear that this method does not take any parameters; if any parameter will be passed then it will raise an error.

Python String isalpha(): Returned Values

This method returns true if all characters of a string are Alphabets.

  • If a string does not contain any alphabet or if the string contains special characters or numerical characters; then this method will return false.

In the case of whitespace, this method also returns false.

Python String isalpha(): Basic Example

Below we have an example to show the working of String isalpha() function:

string = "HelloStudyTonight"
string2 = "Hello StudyTonight"
print("It returns true because string contains alphabets only:")
print("String=", string)
print(string.isalpha())

print("It will return false as it contains alphabets and one space:")
print("String=", string2)
print(string2.isalpha())

The Output will be:


It returns true because string contains alphabets only:
String= HelloStudyTonight
True
It will return false as it contains alphabets and one space:
String= Hello StudyTonight
False

Time For an Example!

Let us see Live Example which is given below where we use isalpha() method in different ways:

Summary

In this tutorial, we discussed isalpha() method with its basic syntax, Returned Values, and Live example.



About the author:
Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.