christoss
christoss

Reputation: 90

Python syntax error?? (except ValueError)

Code:

def is_num(num1):
    try:
        int(num1)
        return True
    except ValueError:
        return False

Consol Output:

 except ValueError:
     ^

SyntaxError: invalid syntax

I started python about 5 days ago so I don't relly understand the error or how to fix it. Please help.

Upvotes: 1

Views: 1823

Answers (1)

wa11a
wa11a

Reputation: 181

You forgot to indent the function body This is working :

def Foo():
    try:
        raise Exception("error")
    except Exception :
        print "test"

Upvotes: 2

Related Questions