[Tutor] __abs__() not acting as expected

Danny Yoo dyoo at hashcollision.org
Mon Mar 24 19:13:21 CET 2014


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
            on 3

whereas you might expecting:

    the __abs__() method
        on -3


English has an analogous problem, as do a lot of languages:

    http://en.wikipedia.org/wiki/List_of_linguistic_example_sentences#Syntactic_ambiguity

where it's easy to misinterpret what the meaning of sentences are,
either because they have an unexpected parse tree, or there are
multiple parse trees, where the meaning becomes ambiguous.


In the case of Python, ambiguity isn't the issue, but the way that the
program parses may be in a particular segmentation that you might not
expect at first.


More information about the Tutor mailing list