如果字符串中的所有字符均为字母,Python的 isalpha()方法将返回true。如果字符不是字母,则返回False。它返回True或False。
isalpha - 语法
isalpha()
isalpha - 返回
它返回True或False。
让无涯教程看一下isalpha()方法的一些例子,以了解其功能。
# Python isalpha() method example # 变量声明 str = "Learnfk" # 函数调用 str2 = str.isalpha() # 显示结果 print(str2)
输出:
True
isalpha - Python String isalpha()方法示例2
# Python isalpha() method example # 变量声明 str = "Welcome to the Learnfk" # 函数调用 str2 = str.isalpha() # 显示结果 print(str2)
输出:
False
isalpha - Python String isalpha()方法示例3
# Python isalpha() method example # 变量声明 str = "Learnfk" if str.isalpha() == True: print("String contains alphabets") else: print("Stringn contains other chars too.")
输出:
String contains alphabets