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
1 2 3 |
isalpha() |
Parameter
NA
Return
This method returns a boolean value true if all characters in the string are alphabetic.
Example 1
1 2 3 4 5 6 7 8 9 10 |
# 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
1 2 3 |
The' JulyApril ' contains all alphabetic value: True |
Example 2
1 2 3 4 5 6 7 8 9 10 11 |
# 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
1 2 3 |
All the characters of the specified string are alphabtes. |
Example 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# 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
1 2 3 4 5 6 |
True False False False |