1. 程式人生 > >isdigit()方法

isdigit()方法

isdigit()方法

描述

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

語法

isdigit()方法語法:

str.isdigit()

引數

  • 無。

返回值

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

例項

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

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

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

# 結果為
# True
# False