On Jul 16, 7:10 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote: > Hi, > > The string format operator, %, provides a functionality similar to the > snprintf function in C. In C, the function does not know the type of > each of the argument and hence relies on the embedded %<char> > specifier to guide itself while retrieving args. > > In python, the language already provides ways to know the type of an > object. > > So in > > output = '%d foo %d bar" % (foo_count, bar_count), > why we need to use %d? In order to distinguish between, for example:
>>> '%c' % 42 '*' >>> '%d' % 42 '42' >>> '%e' % 42 '4.200000e+01' >>> '%f' % 42 '42.000000' >>> '%g' % 42 '42' >>> '%i' % 42 '42' >>> '%o' % 42 '52' >>> '%r' % 42 '42' >>> '%s' % 42 '42' >>> '%u' % 42 '42' >>> '%x' % 42 '2a' -- http://mail.python.org/mailman/listinfo/python-list