[Tutor] Asterisk

alan.gauld@bt.com alan.gauld@bt.com
Sun Dec 8 18:07:23 2002


Catching up on old digests...

> >Why does this happen? It is a strange expression.
> >>>>'%*.*f' % (6,3,1.41421356)
> >' 1.414'

Had me beat!

>  >>> "%*.*f" % (6,3,1.41421356)
> ' 1.414'
>  >>> "%*.*f" % (10,5,1.41421356)
> '   1.41421'

Ah, I see!
Awesome. I've been doing it using two format strings:

fmt = "%%d.%df" % (width, precision)
print fmt % value

The asterisk notation is neat, but I'd never have guessed it!

Thanks for that one Adam and Gregor.