python isdigit()
用的Python 3.7.0 Shell学到005
想测试一下,s.isdigit(), 出现如下报错,不知为啥,求赐教,感谢。
>>> s = 3.0
>>> s.isdigit()
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
s.isdigit()
AttributeError: 'float' object has no attribute 'isdigit'
>>> s = 3
>>> s.isint()
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
s.isint()
AttributeError: 'int' object has no attribute 'isint'
>>>
isdigit() 是只属于字符串的方法,只能用于字符串:
>>> s = '3'
>>> s.isdigit()
True
>>> s = 'abc'
>>> s.isdigit()
False zltzlt 发表于 2020-7-19 20:54
isdigit() 是只属于字符串的方法,只能用于字符串:
谢谢!
页:
[1]