In a dynamic language, why % operator asks user for type info?
Kay Schluehr
kay.schluehr at gmx.net
Tue Jul 17 00:51:47 EDT 2007
On Jul 17, 3:10 am, Karthik Gurusamy <kar1... at gmail.com> wrote:
> output = '%d foo %d bar" % (foo_count, bar_count),
> why we need to use %d? I'm thinking some general common placeholder,
> say %x (currently it's hex..) could be used.
You already answered it in the parenthesized remark: the %d
placeholder is not only type bound but provides an additonal
distinction e.g. the one between decimals and hexadecimals. The kind
of general placeholder you want %x being requested for is actually %s
which formats decimals quite well unless you want leading zeros.
More information about the Python-list
mailing list