except Statement with Multiple Exceptions : Error Exception : Statement PYTHON TUTORIALS


PYTHON TUTORIALS » Statement » Error Exception »

 

except Statement with Multiple Exceptions


def safe_float(obj):
    try:
        retval = float(obj)
    except (ValueError, TypeError):
        retval = 'argument must be a number or numeric string'
    return retval

safe_float('Spanish Inquisition')
safe_float([])
print safe_float('1.6')
print safe_float(1.6)
print safe_float(932)



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Statement
» Error Exception