On 3/4/2021 4:28 PM, Terry Reedy wrote:

Quentin privately sent me 12 lines (which should have been posted here instead), which can be reduced to the following 4 that exhibit his bug.

if a == b:
     print('correct')
     if a != b:
         print('incorrect')

The bug is a != b will never be true when a == b and will not be tested when a != b.  The fix is to use else.

if a == b:
     print('correct')
else:
     print('incorrect')

This should not be reduced to a conditional expression since different code follows the print statements in the actual example.

Quentin wrote me privately that this, applied to his code, solved his problem.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to