Problem with printing statement when condition is false
Terry Reedy
tjreedy at udel.edu
Thu Mar 4 22:13:24 EST 2021
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
More information about the Python-list
mailing list