Python String isalpha() Method



The python string isalpha() method is used to check whether the string consists of alphabets. This method returns true if all the characters in the input string are alphabetic and there is at least one character. Otherwise, it returns false.

Alphabetic characters are those characters defined in the Unicode character database as “Letter”, i.e., those with general category property being one of “Lm”, “Lt”, “Lu”, “Ll”, or “Lo”. Note that this is different from the “Alphabetic” property defined in the Unicode Standard.

Let us look into this function with more details in the following section.

Syntax

Following is the syntax for the python string isalpha() method −

str.isalpha()

Parameters

The python string isalpha() method doesnot contain any parameters.

Return Value

The python string isalpha() method returns true if all characters in the string are alphabetic and there is at least one character and false otherwise.

Example

The lowercase and uppercase alphabets come under alphabetic characters. The other characters such as '!'. '@', ... are not considered as alphabetic.

str = "Hello!welcome"
result=str.isalpha()
print("Are all the characters of the string alphabetic?", result)

On executing the above program, the following output is generated -

Are all the characters of the string alphabetic? False

Example

Only the lowercase and uppercase alphabets come under alphabetic characters.

The following is an example of the python string isalpha() method. In this program, a string "Welcome" is created and the isalpha() function is invoked.

str = "Welcome"
result=str.isalpha()
print("Are all the characters of the string alphabetic?", result)

The following is the output obtained by executing the above program -

Are all the characters of the string alphabetic? True

Example

Only the lowercase and uppercase alphabets come under alphabetic characters. Even an empty space " " is not considered as alphabetic.

str = "welcome "
result=str.isalpha()
print("Are all the characters of the string alphabetic?", result)

The following output is obtained by executing the above program -

Are all the characters of the string alphabetic? False

Example

Only the lowercase and uppercase alphabets come under alphabetic characters.

str = "aBCD"
result=str.isalpha()
print("Are all the characters of the string alphabetic?", result)

The above program, on executing, displays the following output -

Are all the characters of the string alphabetic? True

Example

The lowercase alphabets and uppercase alphabets are considered as alphabetic characters. Even the numbers and empty spaces are not considered as alphabetic.

str = "Welcome to Tutorialspoint12"
result=str.isalpha()
print("Are all the characters of the string alphabetic?", result)

The output of the above program is displayed as follows -

Are all the characters of the string alphabetic? False
python_strings.htm
Advertisements