format sring question
Lowell Kirsh
lkirsh at cs.ubc.ca
Fri Sep 3 03:16:20 EDT 2004
In Peter Norvig's Infrequently Answered Questions he explains that the
following 2 fnctions look almost identical but are not the same:
def printf(format, *args): print format % args,
def printf(format, *args): print str(format) % args,
The only difference is that in the second one, str(format) replaces
format. If args are not given and the format string contains a '%', the
first will work but the second will not. Why is this so? It seems to me
like '100%' and str('100%) are the same object, no?
Lowell
More information about the Python-list
mailing list