def minimalNumber(x):
    if type(x) is str:
        if x == '':
            x = 0
f = float(x)
if f.is_integer():
    return int(f)
else:
    return f
Python string interpolation: only show necessary decimal places