在Python中,isalpha()是用于字符串处理的内置方法。如果字符串中的所有字符都是字母,则isalpha()方法返回“True”,否则,返回“False”。此函数用于检查参数是否包含任何字母字符,例如:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
用法:
string.isalpha()
参数:
isalpha() does not take any parameters
返回:
1.True- If all characters in the string are alphabet.
2.False- If the string contains 1 or more non-alphabets.
例子:
Input:string = 'Ayush'
Output:True
Input:string = 'Ayush Saxena'
Output:False
Input:string = 'Ayush0212'
Output:False
# Python code for implementation of isalpha()
# checking for alphabets
string = 'Ayush'
print(string.isalpha())
string = 'Ayush0212'
print(string.isalpha())
# checking if space is an a