Python3 isdigit()方法

Python3 字符串 Python3 字符串


描述

Python isdigit() 方法檢測字符串是否只由數字組成。

語法

isdigit()方法語法:

str.isdigit()

參數

  • 無。

返回值

如果字符串只包含數字則返回 True 否則返回 False。

實例

以下實例展示了isdigit()方法的實例:

#!/usr/bin/python3

str = "123456"; 
print (str.isdigit())

str = "W3CSchool example....wow!!!"
print (str.isdigit())

以上實例輸出結果如下:

True
False

Python3 字符串 Python3 字符串