Python isdigit()方法
sdigit()方法就是檢測字符串是否只有數字組成,
如果字符串中是只有數字組成,則返回true,
如果字符串中有其他字符,則返回false。
語法格式是: str.isdigit()
#!/usr/bin/python str = "123456"; # Only digit in this string print str.isdigit(); str = "this is string example....wow!!!"; print str.isdigit();
輸出結果:
True
False
