[Tutor] A file containing a string of 1 billion random digits.

Richard D. Moores rdmoores at gmail.com
Mon Jul 19 19:58:50 CEST 2010


On Mon, Jul 19, 2010 at 10:18, ALAN GAULD <alan.gauld at btinternet.com> wrote:
> Wikipedia is a little more helpful but not Python oriented:
>
> http://en.wikipedia.org/wiki/Printf#printf_format_placeholders

Yes, that's helpful.

Say, I found a use for that asterisk in this little function I just wrote:
def sig_digits(n,digits):
    """
    Return any real number n to d significant digits.
    """
    return '%.*g' % (digits, n)

n = -12.22345**.978
digits = 5
x = sig_digits(n, digits)
print(x)

OUTPUT: -11.568

Dick


More information about the Tutor mailing list