String formatting with %s

Donn Ingle donn.ingle at gmail.com
Sun Dec 2 08:35:06 EST 2007


Hi,
 I'm sure I one read somewhere that there is a simple way to set the order
of replacements withing a string *without* using a dictionary.

What I mean is:
>>> s = "%s and %s" % ( "A", "B" )
>>> print s
A and B

Now, is there something quick like:
>>> s = "%s/2 and %s/1" % ( "A", "B" )
>>> print s
B and A

?

I know it can be done with a dict:
d = { "one" : "A", "two" : "B"  }
s = "%(two)s and %(one)s" % d


\d




More information about the Python-list mailing list