python - 检查列表值

标签 python

我有一个只能包含整数的列表,如果它不是整数,我将如何继续控制列表中的每个元素并返回消息?

我可以以某种方式使用 isdigit() 吗?

谢谢

最佳答案

您可以使用all和抽象基类Number :

>>> all(isinstance(x, Number) for x in mylist)

关于python - 检查列表值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7259188/

相关文章:

python - 改变单词的一部分

python - 在for循环中将文件上传到gs存储桶

python - 使用 Python-Xarray 重新网格化坐标

python - 为属性提供自定义 __str__ 表示

python - sympy:求解二次方程的结果顺序

python - ubuntu安装opencv2.4编译报错

python - 无效参数错误 : computed output size would be negative

python - 类型错误 : unorderable types: NoneType() > int()

python - 将 CSV 导入 BigQuery 中的表时无法添加字段

python - 从两个 Pandas 字段创建字典字段