If you are looking for a parsing int instead of floats you can try isdigit() function as string objects.
e.g:
x = "74897"
x.isdigit()
True
y = "7687wa"
y.isdigit()
False
For different approach and accurate result you can use the code:
def My_number_tryexcept(x):
""" Returns True if string is a number. """
try:
float(x)
return True
except ValueError:
return False
import re
def My_number_regex(x):
""" Returns True is string is a number. """
if re.match("^\d+?\.\d+?$", x) is None:
return x.isdigit()
return True
def My_number_repl_isdigit(x):
""" Returns True if string is a number. """
return x.replace('.','',1).isdigit()
Try except method that handels scientific notations correctly
funcs = [
My_number_tryexcept,
My_number_regex,
My_number_repl_isdigit
]
x_float = '.1234'
print('Float notation ".1234" is not supported by:')
for f in funcs:
if not f(x_float):
print('\t -', f.__name__)
:Let me know if it is working or not.