I feel a bit silly for asking what I’m sure is a rather basic question, but I’ve been learning Python and I’m having difficulty understanding what exactly the “g” and “G” string formats actually do.
The documentation has this to say:
Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
I’m sure this is supposed to make sense, but I’m just not getting it. Can someone provide a clearer explanation for this format, and possibly provide some examples of when and how it should be used, vs. just using “e” or “f”.
Thanks
These examples are probably illustrative:
One of the nice things about Python is that it is easy to test something out in the interpreter when you don’t understand exactly what it means.