Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6887267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:51:51+00:00 2026-05-27T05:51:51+00:00

I feel a bit silly for asking what I’m sure is a rather basic

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:51:52+00:00Added an answer on May 27, 2026 at 5:51 am

    These examples are probably illustrative:

    >>> numbers = [100, 10, 1, 0.1, 0.01, 0.001, 0.0001, 0.00001]
    >>> for number in numbers:
    ...     print "%%e=%e, %%f=%f, %%g=%g" % (number, number, number)
    ... 
    %e=1.000000e+02, %f=100.000000, %g=100
    %e=1.000000e+01, %f=10.000000, %g=10
    %e=1.000000e+00, %f=1.000000, %g=1
    %e=1.000000e-01, %f=0.100000, %g=0.1
    %e=1.000000e-02, %f=0.010000, %g=0.01
    %e=1.000000e-03, %f=0.001000, %g=0.001
    %e=1.000000e-04, %f=0.000100, %g=0.0001
    %e=1.000000e-05, %f=0.000010, %g=1e-05
    >>> for number in numbers:
    ...     print "%%0.2e=%0.2e, %%0.2f=%0.2f, %%0.2g=%0.2g" % (number, number, number)
    ... 
    %0.2e=1.00e+02, %0.2f=100.00, %0.2g=1e+02
    %0.2e=1.00e+01, %0.2f=10.00, %0.2g=10
    %0.2e=1.00e+00, %0.2f=1.00, %0.2g=1
    %0.2e=1.00e-01, %0.2f=0.10, %0.2g=0.1
    %0.2e=1.00e-02, %0.2f=0.01, %0.2g=0.01
    %0.2e=1.00e-03, %0.2f=0.00, %0.2g=0.001
    %0.2e=1.00e-04, %0.2f=0.00, %0.2g=0.0001
    %0.2e=1.00e-05, %0.2f=0.00, %0.2g=1e-05
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel a little bit silly asking this, but I haven't been able to
As a Rails developer I feel a bit stupid asking this question but hopefully
Feel a bit silly asking this on here but I'm at a loose end
I feel a bit embarrassed asking this questions, but how the heck can I
I feel a bit silly asking this as the answer is bound to be
I feel a bit silly for this one, but is there a more elegant
I have recently started exploring Maven, but I feel a bit overwhelmed of all
This is a bit of a Visual Studio question. I feel with all the
Feel free to close and/or redirect if this has been asked, but here's my
Ok, I feel a bit dumb having to ask this. There are any number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.