Answers for "Value Error handling"

0

Value Error handling

def conv(s):
    try:
        s=float(s)
    except ValueError:
        pass    
    return s

print [conv(s) for s in ['1.1','bls','1','nan', 'not a float']] 
# [1.1, 'bls', 1.0, nan, 'not a float']
Posted by: Guest on July-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language