Python - AttributeError: 'str' object has no attribute 'isDigit'
Python - AttributeError: 'str' object has no attribute 'isDigit'
这是我的代码
input = raw_input("Please enter a number")
print input.isDigit()
当我将输入 7 输入解释器时,它会抛出错误:
AttributeError: 'str' object has no attribute 'isDigit'
这是没有意义的,因为 isDigit
是一个内置函数,用于字符串。我正在使用 python 2.7 并且我正在使用 JetBrains Pycharm 所以它可能是我正在使用的 IDE 吗?
D
必须是小写字母(小写字母)。
print input.isdigit()
并且不要使用内置关键字作为变量名。
>>> inp = raw_input("Please enter a number: ")
Please enter a number: 5
>>> print inp.isdigit()
True
var= '10'
if(var.isdigit()):
print "has only digits"
else:
print "has something else"
您错误地使用了 isdigit() 方法,请记住 python 区分大小写并且您必须在 isdigit() 中使用小写 d。
这是我的代码
input = raw_input("Please enter a number")
print input.isDigit()
当我将输入 7 输入解释器时,它会抛出错误:
AttributeError: 'str' object has no attribute 'isDigit'
这是没有意义的,因为 isDigit
是一个内置函数,用于字符串。我正在使用 python 2.7 并且我正在使用 JetBrains Pycharm 所以它可能是我正在使用的 IDE 吗?
D
必须是小写字母(小写字母)。
print input.isdigit()
并且不要使用内置关键字作为变量名。
>>> inp = raw_input("Please enter a number: ")
Please enter a number: 5
>>> print inp.isdigit()
True
var= '10'
if(var.isdigit()):
print "has only digits"
else:
print "has something else"
您错误地使用了 isdigit() 方法,请记住 python 区分大小写并且您必须在 isdigit() 中使用小写 d。