当前位置:  首页>> 技术小册>> Python合辑2-字符串常用方法

18、isnumeric()

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

  1. s = 'python'
  2. print(s.isnumeric())
  3. # False
  4. s = '123'
  5. print(s.isnumeric())
  6. # True
  7. s = 'python123'
  8. print(s.isnumeric())
  9. # False
  10. s = 'python-123'
  11. print(s.isnumeric())
  12. # False