Python String Substitution

Murali maha.murali at
Thu Jan 26 18:40:47 EST 2006

In Python, dictionaries can have any hashable value as a string. In
particular I can say

d = {}
d[(1,2)] = "Right"
d["(1,2)"] = "Wrong"
d["key"] = "test"

In order to print "test" using % substitution I can say

print "%(key)s" % d

Is there a way to print "Right" using % substitution?

print "%((1,2))s" % d

gives me "Wrong". Is there any syntax which will allow me to get
"Right" using % substitution?

- Murali

More information about the Python-list mailing list