[Tutor] How to substitute an element of a list asapattern forre.compile()

Alan Gauld alan.gauld at freenet.co.uk
Sun Jan 2 09:26:09 CET 2005


> >   >>> for x in ['string', 10, True, [1,2,3] ]:
> >   ...   print '%s' %x
> >   ...
> > string
> > 10
> > True
> > [1, 2, 3]
> 
> That's cool! I didn't know that. I guess I'm crazy... : )
> (We already knew that here.)

The difference is in how the formatting details work.
For numbers the formatting digits indicate precision 
and for strings length.

>>> print "%5.3f" % 123.456
123.4560
>>> print "%5.3s" % 123.456
 123.

produce very different results.

Alan G.


More information about the Tutor mailing list