isdigit() 方法檢查字串是否只包含數字。
語法
以下是 isdigit() 方法的語法 -
str.isdigit()
參數
-
NA
返回值
如果在字串中的所有字元是數字,並 str 至少有一個字元此方法返回true,否則返回 false。
示例
下麵的示例顯示 isdigit() 方法的使用。
#!/usr/bin/python3 str = "123456"; # Only digit in this string print (str.isdigit()) str = "this is string example....wow!!!" print (str.isdigit())
當我們運行上面的程式,會產生以下結果 -
True False