📅  最后修改于: 2020-10-30 06:17:15             🧑  作者: Mango
如果字符串中的所有字符均为字母, Python的isalpha()方法将返回true。如果字符不是字母,则返回False。它返回True或False。
isalpha()
不需要任何参数。
它返回True或False。
让我们看一下isalpha()方法的一些例子,以了解它的功能。
# Python isalpha() method example
# Variable declaration
str = "Javatpoint"
# Calling function
str2 = str.isalpha()
# Displaying result
print(str2)
输出:
True
# Python isalpha() method example
# Variable declaration
str = "Welcome to the Javatpoint"
# Calling function
str2 = str.isalpha()
# Displaying result
print(str2)
输出:
False
# Python isalpha() method example
# Variable declaration
str = "Javatpoint"
if str.isalpha() == True:
print("String contains alphabets")
else: print("Stringn contains other chars too.")
输出:
String contains alphabets