如果字符串中的所有字符均为字母,Python的
它返回True或False。
让无涯教程看一下isalpha()方法的一些例子,以了解其功能。
# Python isalpha() method example # 变量声明 str = "Learnfk" # 函数调用 str2 = str.isalpha() # 显示结果 print(str2)
输出:
True
# Python isalpha() method example # 变量声明 str = "Welcome to the Learnfk" # 函数调用 str2 = str.isalpha() # 显示结果 print(str2)
输出:
False
# Python isalpha() method example # 变量声明 str = "Learnfk" if str.isalpha() == True: print("String contains alphabets") else: print("Stringn contains other chars too.")
输出:
String contains alphabets
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)