How is the isalpha method used in Python?
In Python, isalpha() is a string method used to check if a string contains only alphabetic characters. It returns a boolean value – True if the string has at least one character and all characters are alphabetic, otherwise False.
Here is an example of how to use isalpha():
string1 = "Hello"
print(string1.isalpha()) # True
string2 = "Hello123"
print(string2.isalpha()) # False
string3 = ""
print(string3.isalpha()) # False
string4 = "123"
print(string4.isalpha()) # False
In the example above, the isalpha() method is used to check the character type in a string. It returns True if the string contains only letters, otherwise it returns False.