Perl is worse!
Alex Martelli
alex at magenta.com
Fri Jul 28 17:38:35 EDT 2000
<gbreed at cix.compulink.co.uk> wrote in message
news:8lsdir$aja$1 at plutonium.compulink.co.uk...
[snip]
> x = "11"
> y = 22
> z = x+y
>
> is ambiguous. Different languages define it different ways. That's fine,
> as far as the machine's concerned. But a poor human being could misread
> it. In fact, before this thread came up, I assumed Python coerced the int
> to a string, like Java and Visual Basic do. You assumed it should do the
No; in Visual Basic this leaves 33 in z. VB's + concatenates string if
both operands are strings, so if y = "22" then z ends up with "1122",
but if either is integer it's the string that gets coerced (with a runtime
error -- rough equivalent of an exception, and trappable -- if it's
imperfect, e.g. x = "11a" above). & is VB's always-string-concat
operator (and coerces-to-string both operands).
Alex
More information about the Python-list
mailing list