Mega Code Archive

 
Categories / Python Tutorial / Statement
 

Try Statement with Multiple excepts

def safe_float(obj):     try:          retval = float(obj)     except ValueError:         retval = 'could not convert non-number to float'     except TypeError:         retval = 'object type cannot be converted to float'     return retval