import re string = """12345 67890 afghe abcde 23456 0abcd 34567 __fred01 45678 123.456 12345a 123. .456 ab00cd 00ab00""" for m in string.split(): if m.isdigit(): print(m, 'Int') else: try: float(m) print(m, 'Float') except ValueError: print(m, 'STR')
Standard input is empty
('12345', 'Int') ('67890', 'Int') ('afghe', 'STR') ('abcde', 'STR') ('23456', 'Int') ('0abcd', 'STR') ('34567', 'Int') ('__fred01', 'STR') ('45678', 'Int') ('123.456', 'Float') ('12345a', 'STR') ('123.', 'Float') ('.456', 'Float') ('ab00cd', 'STR') ('00ab00', 'STR')