How do I check if raw input is integer in python 2.7?
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 isinstance(raw_input("number: ")), int) but when I run it and input 4 for example, I get FALSE . I'm kind of new to python, any help would be appreciated. isinstance(raw_input("number: ")), int) always yields False because raw_input return string object as a result. Use try: int(...) ... except ValueError : number = raw_input("number: ") try: int(number) except ValueError: print False else: print True or use str.isdigit : print raw_input("number: ").isdigit() NOTE The