Python String isalpha() method
Python String isalpha() method
The string.isalpha () method in Python returns a boolean value true if all characters in the string are alphabetic else for any other value it returns false.
Syntax
isalpha()
Parameter
NA
Return
This method returns a boolean value true if all characters in the string are alphabetic.
Example 1
# Python programing explaining # the isalpha() method # initializing a alhabetic value strVal = "JulyApril"; # returning a boolean value if all the string characters are alphabetic bool= strVal.isalpha() # prinitng the boolean value print("The'",strVal,"' contains all alphabetic value:",bool)
Output
The' JulyApril ' contains all alphabetic value: True
Example 2
# Python programing explaining # the isalpha() method # initializing a string value strVal = "Hello" # validating if and else condition if strVal.isalpha() == True: print("All the characters of the specified string are alphabtes.") else: print("All the characters are not alphabtes.")
Output
All the characters of the specified string are alphabtes.
Example 3
# Python programing explaining # the isalpha() method # initializing a string value char1 = "HelloWorld" # will return true as the string is alphabetic print(char1.isalpha()) # string containing whitespace char2 = "Hello World " # will return False as the string contains whitespace print(char2.isalpha()) #passing special characters char3 = "!Mo3nica*$Gell22er" # will return false as it contains special characters print(char3.isalpha()) # passing alphanumeric char4 = "hello133world"# will return False as it is alphanumeric print(char4.isalpha())
Output
True False False False