I would extract all the numbers contained in a string. Which is the better suited for the purpose, regular expressions or the isdigit() method?
isdigit()
Example:
I am just adding this answer because no one added one using Exception handling and because this also works for floats
a = [] line = "abcd 1234 efgh 56.78 ij" for word in line.split(): try: a.append(float(word)) except ValueError: pass print(a)
Output :
[1234.0, 56.78]