描述

Python isdigit() 方法检测字符串是否只由数字组成。

相近的方法:isnumeric() 方法。

语法

isdigit() 方法语法:

S.isdigit()

参数

  • 无。

返回值

如果字符串只包含数字则返回 True 否则返回 False。

实例

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

#!/usr/bin/python3

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

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

以上实例输出结果如下:

True
False

相关文章:

  • 2021-06-24
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
猜你喜欢
  • 2021-08-26
  • 2021-08-19
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案