[Tutor] __abs__() not acting as expected
Jim Byrnes
jf_byrnes at comcast.net
Mon Mar 24 05:08:35 CET 2014
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
>>> -3 .__abs__()
-3
If I use a variable it works.
>>> x = -3
>>> x.__abs__()
3
I am curious as to what is happening. Is the book wrong? I checked
it's errata and nothing is mentioned.
Regards, Jim
More information about the Tutor
mailing list