Is Python type safe?
mjackson at alumni.caltech.edu
Tue Mar 16 23:07:33 CET 2004
Roy Smith <roy at panix.com> writes:
> 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.)
> > -Peter
> 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 :-)
And would the result of "quatre" + 7, say, depend on the locale setting?
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
The supreme misfortune is when theory outstrips performance.
- Leonardo da Vinci
More information about the Python-list