In a dynamic language, why % operator asks user for type info?

Miles semanticist at gmail.com
Tue Jul 17 04:03:16 CEST 2007


On Jul 16, 8:10 pm, Karthik Gurusamy <kar1... at gmail.com> wrote:
> Since % by definition is string formatting, the operator should be
> able to infer how to convert each of the argument into strings.

In addition to what Dan mentioned, you can use "%s" with any object to
perform an automatic string conversion.

>>> '%s %s %s %s' % ('Hello!', 3.14, 42+1j, object())
'Hello! 3.14 (42+1j) <object object at 0x41448>'

-Miles




More information about the Python-list mailing list