isalpha() method of str class

The isalpha() of str class returns True only if a string has all alphabets. Returns False if the string has at least on non-alphabet or if the string is empty.

Str Updated 10 Mar 2017 1 min read

Method Name

isalpha

Method Signature

isalpha()

Method Overview

  • If a string object is solely composed of alphabets isalpha()returns True; Returns False otherwise.

  • If the string is empty returns False

Example

python
stmt        = "Honorificabilitudinitatibus"

alphaCheck  = stmt.isalpha()

print("String has only alphabets:{}".format(alphaCheck))

stmt        = ""

alphaCheck  = stmt.isalpha()

print("isalpha() returned:{} for an empty string".format(alphaCheck))

stmt        = "1Two3Four"

alphaCheck  = stmt.isalpha()

print("String has only alphabets:{}".format(alphaCheck))

Output

Output
String has only alphabets:True

isalpha() returned:False for an empty string

String has only alphabets:False