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

 

返回值

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

 

>>> choice = input(">>>:").strip()
>>>:sdfsa
>>>
>>> choice.isdigit()
False
>>>


>>> choice = input(">>>:").strip()
>>>:123
>>> choice.isdigit()
True
>>>

 

python isalnum()  判断所有字符是否数字或者字母 是返回true  否返回false

>>> a = "12345"
>>> a.isalnum()
True
>>>
>>> a = "sadasd"
>>> a.isalnum()
True
>>>
>>> a = ",.."
>>> a.isalnum()
False

 

相关文章:

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