May-23-2022, 09:01 PM
I don't see anything wrong with using a try/except for handling an attempt to see if something is or is not compatible with float().
Float will handle exponential notation while yours will not. Up to you if that's a problem. Yours will not handle negative numbers or numbers with an explicit plus sign.
Float will handle exponential notation while yours will not. Up to you if that's a problem. Yours will not handle negative numbers or numbers with an explicit plus sign.
>>> [float(x) for x in ("1e3", "-12", "+3.5")] [1000.0, -12.0, 3.5]