Hi Jim,
The point the book is trying to make here is purely a parsing problem.
It's trying to say that the expression:
-3.__abs__()
has a parse tree that may be unexpected to beginners. The parse is
analogous to:
unary subtraction on the following:
the __abs__() method
Dave Angel writes:
> Ben is right, dunder methods don't belong in introductory texts.
[…]
> But he didn't show you the simplest fix:
>
> (-3).__abs__()
I disagree; the simplest fix is not to call that method directly, and
just use::
abs(-3)
--
\ “Computer perspective on Moore'
Jim Byrnes Wrote in message:
> I am reading Practical Programming - An Introduction to Computer Science
> Using Python 3. They give this example:
>
> >>> abs(-3)
> 3
>
> >>> -3 .__abs__()
> 3
>
Ben is right, dunder methods don't belong in introductory texts.
And they seldom should be ca
I am reading Practical Programming - An Introduction to Computer Science
Using Python 3. They give this example:
>>> abs(-3)
3
>>> -3 .__abs__()
3
When I try it in idle or a terminal I get different results.
Python 3.3.5 (default, Mar 12 2014, 02:09:17)
[GCC 4.6.3] on linux
>>> abs(-3)
3
>