value error handling

Solutions on MaxInterview for value error handling by the best coders in the world

showing results for - "value error handling"
Ricardo
22 Jun 2016
1def conv(s):
2    try:
3        s=float(s)
4    except ValueError:
5        pass    
6    return s
7
8print [conv(s) for s in ['1.1','bls','1','nan', 'not a float']] 
9# [1.1, 'bls', 1.0, nan, 'not a float']
10