small medium large xlarge

14 Sep 2013, 04:15
Luke Pettit (1 post)

On page 128 it says: The documentation describes when these are called. Here we show both versions of getting the absolute value of a number: (»> abs(-3) 3 »> -3 .abs() 3) yet idle produces this: (»> abs(-3) 3 »> -3 .abs() -3) I don’t think -3 should be the result and that the problem isn’t with your book but just in case. I just cut and pasted all the code so it can’t be my typos

Python version 3.3.2 Tk Version 8.5.11 Idle version 3.3.2

14 Sep 2013, 19:30
Jason Montojo (8 posts)

Hi Luke,

Thanks for catching that! It’s a typo. Because the “.” operator has higher precedence than the unary “-“ operator, this is what ends up happening:

-(3 .__abs__())

…i.e. -(abs(3))

The example should read:

(-3) .__abs__()

You must be logged in to comment