当前位置: 动力学知识库 > 问答 > 编程问答 >

In Python 2.x, is there anyway to check if a string can be converted to an integer?

问题描述:

This question already has an answer here:

  • How do I check if a string is a number (float) in Python?

    29 answers

网友答案:

The best approach here is to just try and convert it and ignore the error if the conversion fails. For example:

try:
    your_list.append(int(user_input))
except ValueError:
    pass
分享给朋友:
您可能感兴趣的文章:
随机阅读: