Is Python type safe?
roy at panix.com
Tue Mar 16 22:32:54 CET 2004
In article <QuJ5c.3008$G3.27398 at localhost>,
Peter Hansen <peter at engcorp.com> wrote:
> Roy Smith wrote:
> > Neither C++ nor Python will let you add the integer 3 to the string
> > "four", but use different mechanisms to prevent it. Oddly enough, Java
> > (in a perl-like, but admittedly convenient, stab at automagic
> > polymorphism) will let you add them. No clue what C# does.
> It's been a while since I Java-ed, but doesn't it "append" them, as in
> convert the integer to a string and then join the two strings, rather
> than "add" them (which I take to mean "calculate the sum of")?
> (That's probably what you meant, but I'm just checking. I'd be
> surprised to find that Java actually performed the string-to-value
> conversion implicitly.)
Yes, "four" + 3 ==> "four3"
I could imagine a language where "4" + 3 ==> 7 (actually, I don't have
to imagine it, all I need do is look at perl). But, a language where
"four" + 3 ==> 7 would be pretty bizarre :-)
More information about the Python-list