问题描述:

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
相关阅读:
Top