Python String isaplha() Method

The isalpha() method returns True if all characters in a string are alphabetic (both lowercase and uppercase) and returns False if at least one character is not an alphabet. The whitespace, numerics, and symbols are considered as non-alphabetical characters.

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".

Syntax:

str.isalpha()

Parameters:

None.

Return Value:

Returns True or False.

The following example demonstrates isalpha() method.

Example:
mystr = 'HelloWorld'
print(mystr.isalpha()) # returns True
mystr = 'Hello World'
print(mystr.isalpha()) # returns False

print('12345'.isalpha()) # returns False
print('#Hundred'.isalpha()) # returns False
Output
True
False
False
Flase

The isalpha() method also identifies unicode alphabets of other international languages. For example, it can check the following German word 'außen'.

Example:
mystr = 'außen'
print(mystr.isalpha()) # Returns True

The isalpha() method can be used to identify non-alphabats in a string, as shown below.

Example:
def printNonAlphabats(mystr):
	print('non-alphabats:', end='')
	for i in mystr:
		if(i.isalpha() == False):
			print(i,end=',')

printNonAlphabata('TutorialsTeacher #1')
non-alphabats: ,#,1,

The following table lists difference among the isalpha(), isalnum(), and isidentifier() methods based on the given inputs:

Input String isaplha() isalnum() isidentifier()
'123' False True False
'$123' False False False
'XYZ123' False True True
'123XYZ' False True False
'_123XYZ' False False True
'_XYZ_123' False False True
'-XYZ-123' False False False
'.XYZ.123' False False False
Want to check how much you know Python?