1

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.

3
  • I got this syntax error when i run it and i dont know why Commented Sep 8, 2015 at 7:33
  • The code you posted here is valid Python code. Are you 100% certain there is no other code or that your indentations are correct (tabs vs spaces)? Commented Sep 8, 2015 at 7:34
  • 2
    I notice your original source as pasted uses tabs, for example. Commented Sep 8, 2015 at 7:34

1 Answer 1

2

You forgot to indent the function body This is working :

def Foo():
    try:
        raise Exception("error")
    except Exception :
        print "test"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.