Python 字符串方法

Python str.isalpha() 方法用于判断字符串是否全部是字母

语法

s.isalpha()

参数

无参数。

返回值

返回布尔值:字符串非空且全部是字母(含中文)则为 True。

示例

print("hello".isalpha())     # True
print("hello123".isalpha())  # False
print("hello world".isalpha())  # False,含空格
print("中文".isalpha())      # True,中文字母也算
print("".isalpha())          # False

输出:

True
False
False
True
False

注意事项

中文也被 isalpha 视为字母。含数字、空格、符号都返回 False。