python - 检测字符串中的数字

标签 python

value = 'ad.41.bd'

if len(value) == len(value.strip({0,1,2,3,4,5,6,7,8,9})):
    # no numbers
else:
    # numbers present

在 Python 中有更简洁的方法来检测字符串中的数字吗?

最佳答案

这个呢?

import re
if not re.search('\d+', value):
    # no numbers
else:
    # numbers present

关于python - 检测字符串中的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6649096/

相关文章:

python - 如何使用每个模块的测试数据初始化数据库? Pytest-django

python - Nginx:加快图像上传速度?

python - 将多个数据框合并在一起

python - matplotlib.pyplot.draw() 和 matplotlib.pyplot.show() 没有效果

python - 为什么 boost::python 迭代器会跳过第一个元素?

python - 在 Google Colab Pro 中使用 TPU v3

python - 属性错误 : 'module' object has no attribute 'Spider'

python - 忘记从函数返回结果 : how to prevent this bug?

python - Django fixture 数据没有有效的模型标识符?

python - 将数据库查询转换为有用的格式