[Tutor] Lists on the fly?
Alan Gauld
alan.gauld at btinternet.com
Sat Dec 23 10:16:53 CET 2006
"Luke Paireepinart" <rabidpoobear at gmail.com> wrote
>>> 'list_%i' % (i) = []
>>>
> Note, though this is pretty arbitrary :) and only saves you 2
> characters...
> You don't need to create a tuple if you're only packing in one
> value.
> >>> i = 1
> >>> 'list_%i' % i
And that works for multiple values provided they are unambiguous.
"%d,%d,%d" % 1,2,3
You need the parens if the substitution values are more complex
and include operators:
"%d,%d,%d" % 1, 2, 1+2
Will give an error (adding int to string) you need the parens here:
"%d,%d,%d" % (1, 2, 1+2)
HTH,
Alan G
More information about the Tutor
mailing list