How do I check if raw input is integer in python 2.7?

前端 未结 5 1289
庸人自扰
庸人自扰 2020-11-28 15:28

Is there a method that I can use to check if a raw_input is an integer?

I found this method after researching in the web:

print isinsta         


        
5条回答
  •  -上瘾入骨i
    2020-11-28 16:21

    You can do it this way:

    try:
        val = int(raw_input("number: "))
    except ValueError:
        # not an integer
    

提交回复
热议问题