[Tutor] Numbers & Characters As Dictionary Keys
alan.gauld at freenet.co.uk
Tue Jun 21 18:47:41 CEST 2005
> > print "%s\t%s" % (m,menu[m])
> I am curious what the "%" by itself is doing.
Its a standard string formatting operation in Python.
The % operator basically says substitute the values
in the folowing tuple for the marked fields in the
The print statement above therefore is roughly equivalent
print m + '\t' + menu[m]
But the formatting markers allow you to add formatting
data like the minimum number of characters, right/left
justification, number of digits after a decimal point,
hex or decimal display of numbers etc etc.
Take a look in the Python docs for string formatting.
More information about the Tutor