Little problem with the "+" operator

Steve Holden sholden at holdenweb.com
Mon Mar 5 20:57:15 EST 2001


"Jay O'Connor" <joconnor at cybermesa.com> wrote in message
news:3aa3d3a7.420988249 at news.uswest.net...
> On 05 Mar 2001 09:38:49 -0800, Johann Hibschman
> <johann at physics.berkeley.edu> wrote:
>
> >Joshua Marshall writes:
> >
> >>> This is infinitely more sane than:
> >
> >>> % perl -e 'print 500 + "cool"'
> >>> 500
> >
> >> Comparing Python to Perl here doesn't seem very fair.  They're very
> >> different languages.  In general, I'm surprised by the urgency with
> >> which people often jump to compare them.
> >
> >Well, Perl's the only language that I know of that lets you add 500 to
> >"cool" without an error.  Well, I suppose tcl might.  But it's still a
> >fairly safe inference that the original poster was coming from Perl.
>
>
> Actually, JavaScript will allow you to add numbers to strings, with
> weird results
>
> '100' + 200 = '100200'
> 100 + '200' = 300
>
> I *think* that's how it works, I just know it's not very safe
>
Kind of "operator underloading"?

too-bad-a-typist-to-program-in-java-ly y'rs  -steve






More information about the Python-list mailing list