What is the best possible way to check if a string can be represented as a number in Python?
The function I currently have right now is:
def is_numb
RyanN suggests
If you want to return False for a NaN and Inf, change line to x = float(s); return (x == x) and (x - 1 != x). This should return True for all floats except Inf and NaN
But this doesn't quite work, because for sufficiently large floats, x-1 == x
returns true. For example, 2.0**54 - 1 == 2.0**54