[Python-ideas] String interpolation again.

Masklinn masklinn at masklinn.net
Fri Jul 23 15:25:42 CEST 2010

On 2010-07-23, at 15:05 , Mike Meyer wrote:
> The first problem with this kind of thing is that there's no obvious
> reason why 12 + '34' should be '1234' instead of 46.
> Java variables have declared types. This means the above situation can
> be detected at compile time, and the implicit conversion added
> then. In Python, you have to do the tests at run time, which will slow
> everything down.
Actually, it's much simpler than that for Java: the `+` operator is specially overloaded any time a string is involved to become a "convert and concatenate" operator similar to PHP's "." rather than the usual "add" operator.

In Python, the equivalent behavior would be to special case the addition operator so that it checks if either operand is a string and if it is convert and concatenate the other one, otherwise apply normal resolution.

More information about the Python-ideas mailing list