字符串方法描述:
Python isdigit() 方法检测字符串是否只由数字组成。
语法:
str.isdigit()
参数:
无
返回值:
如果字符串只包含数字则返回True,否则返回False
实列:
str = "123456"
print str.isdigit()
str = "this is string example....wow!!!"
print str.isdigit()
结果:
True
False
结合input实列:
str_a = input('请输入一个5位数,判断是否为回文数(方法一):')
if str_a.isdigit() and len(str_a) == 5 and str_a[0] != '0':
print(True)
else:
print(False)