On Wed, Nov 16, 2011 at 10:09 AM, Steven D'Aprano <st...@pearwood.info>wrote:
> Wayne Werner wrote: > <snip> > >> In old style formatting, you use a string with format specifiers (%s, %d, >> etc.) followed by a tuple of arguments. Here, the lengths have to match >> exactly - if you have one specifier then you must have a 1-element tuple. >> > > That's actually wrong. If you have one specifier, you must have one object > of any sort *except* a tuple. I think you misunderstood - I said a 1-element tuple - e.g. (3,) > >>> "%s" % 42 # One object not a tuple. > '42' > > But if you have a tuple, the % formatting will try to use each element in > the tuple separately: > > >>> "%s" % (23, 42) # One object which is a tuple > As above, that's a two-element tuple. It was explained to me once that in this case: "%s" % 42 That since python expects to see a single-element tuple it treats it as or converts 42 to a single element tuple. I suppose I could have called it a tuple of length 1 instead. Sorry for the mistunderstanding, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor