Answer the question
In order to leave comments, you need to log in
How to filter real numbers from string in python?
It is necessary to make a filter for real numbers. What method can be used for this? I found that 3 methods can be suitable for integers:
isdigit()
isnumeric()
isdecimal()
But nothing for fractions. How can I do that?
Answer the question
In order to leave comments, you need to log in
Regulators as an option:
import re
data = ['erwer', 'dd', '44j', '5.09', '33', 'dfgdfs', '99.100', '5645..99', '.434', '42342.']
[x for x in data if re.match('^\d+(\.\d){0,1}\d*$', x)]
['5.09', '33', '99.100']
def is_float(value):
try:
float(value)
except ValueError:
return False
return True
>>> is_float('65456')
True
>>> is_float('65456.00')
True
>>> is_float('65456.00gfghf')
False
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question