i have a file of this开发者_如何转开发 format:
3.334 1
2.345 1
1.453 1
3.343 1
and so on
but in middle at times in file there are few number which are not in float format and i receive type msg when i run them performation some operation..
I want to give a condition that:
if(not in float format):
continue
else:
perform operation
please tell me how to put the condtion
You can use an exception handler:
try:
f = float(thing)
except ValueError:
# This is not a float
f = 0.0
ValueError
is thrown by invalid conversions. You should have seen it in your application traceback when an invalid float value conversion was tried.
精彩评论