Comparison Style

Terry Jan Reedy tjreedy at udel.edu
Sat Apr 27 17:40:46 EDT 2013


On 4/27/2013 5:03 PM, Roy Smith wrote:
> In article <mailman.1077.1366944517.3114.python-list at python.org>,
>   Chris Angelico <rosuav at gmail.com> wrote:
>
>> If you switch the order of operands in that, the compiler won't help
>> you. Plus it "reads" wrong. So the convention is still
>> variable==constant.
>
> I just found a nice example of putting the constant first.  I've just
> done a whole bunch of ugly math to find some slice limits.  To make sure
> they're sane, I'm writing:
>
>          assert 5 <= i < j < original_song_count
>
> I can't think of any way to write that which would be as clean and easy
> to read.

Chained comparisons like this are standard math notation, which is why 
Python 'does the right thing' with them.






More information about the Python-list mailing list