这是我的代码
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
