我是python新手,字符串有问题。我得到了“attributerror:”str“object没有属性”,但是我很困惑为什么。我已经提供了一些我的代码,所以任何建议都会有帮助!
#Have user enter their string.
string = input("Enter a string: ")
#Find if string only contains letters and spaces
if string.isalpha():
print("Only alphabetic letters and spaces: yes")
else:
print("Only alphabetic letters and spaces: no")
#Find if string is only numeric.
if string.isdigits():
print("Only numeric digits: yes")
else:
print("Only numeric digits: no")
应该是
string.isdigit()
而不是string.isdigits()
相关问题 更多 >
编程相关推荐