Bizarre arithmetic results

Mark Dickinson dickinsm at gmail.com
Tue Feb 23 08:48:09 EST 2010


On Feb 23, 8:11 am, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:
> Making spaces significant in that fashion is mind-bogglingly awful. Let's
> look at a language that does this:
>
> [steve at sylar ~]$ cat ws-example.rb
> def a(x=4)
>     x+2
> end
>
> b = 1
> print (a + b), (a+b), (a+ b), (a +b), "\n"
>
> [steve at sylar ~]$ ruby ws-example.rb
> 7773

Hmm.  That's pretty nasty, all right.  Not that Python can claim to be
immune to such behaviour:

>>> 3 .real
3
>>> 3. real
  File "<stdin>", line 1
    3. real
          ^
SyntaxError: invalid syntax


Though the fact that one of the cases raises an exception (rather than
silently giving some different behaviour) ameliorates things a bit.

--
Mark



More information about the Python-list mailing list