Operator precedence problem

Jon Ribbens jon+usenet at unequivocal.co.uk
Mon Jun 6 11:03:05 EDT 2016


On 2016-06-06, Marko Rauhamaa <marko at pacujo.net> wrote:
> Random832 <random832 at fastmail.com>:
>> Sure, it's obvious to _me_ that << and >> have higher precedence than &
>> and |, and that "and" has a higher precedence than "or", but can I
>> assume the other people know this?
>
> No need to assume. Just read the spec:

The spec tells you the overlap between the set of all people who will
ever read your code and the set of people who have memorised the
entire list of operator precedences in the spec?

That's one impressive spec.

> You *can* assume other people have read the spec. Even more importantly,
> you can assume the Python interpreter complies with the spec.

Obviously the latter is true (or at least, it's true except when it's
false). The former however is not true. You should put brackets around
expressions when it's at all unclear what the meaning is. You could
think of them a bit like "active comments" I suppose.



More information about the Python-list mailing list