Which of the following is the best way of checking if a string could be represented as number?
a)
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
b)
Import re
check_regexp = re.compile(“^\d*\.?\d*$”)
c)
def isNumber(token):
for char in token:
if not char in string.digits: return false
return True
d)
import re
check_replace = lambda x: x.replace(‘.’,’’,1).isdigit()