See PEP 3101:
'g' - General format. This prints the number as a fixed-point number, unless the number is too large, in which case it switches to 'e' exponent notation.
Old style (not preferred):
>>> "%g" % float(10)
'10'
New style:
>>> '{0:g}'.format(float(21))
'21'
New style 3.6+:
>>> f'{float(21):g}'
'21'