Catch data type miss match : Buildin Error « Language Basics « Python






Catch data type miss match

Catch data type miss match

value = "2"

print repr(value), "is ",

try:
    value + 0
except TypeError:
    # not a number, maybe a string, Unicode, UserString...?
    try:
        value + ''
    except TypeError:
        print "neither a number nor a string"
    else:
        print "a string or string-like value"
else:
    print "a number of some kind"

           
       








Related examples in the same category

1.ZeroDivisionError DemoZeroDivisionError Demo