简体   繁体   中英

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.

You forgot to indent the function body This is working :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM