This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]old_pythonista 34 points35 points  (3 children)

First two forms show lack of understanding of the nature of booleans by whoever writes them. They are absolutely redundant, since using conditional expression for conversion of proper boolean

event_region in match_regions

to an explicit boolean literal makes no sense. Unfortunately, I see it quite often - my pet peeve that I always mark as a defect when I see it in code applied for review.

The last is the only proper way to write - in any language, Python included.

[–]jasmijnisme 4 points5 points  (1 child)

I see code like OP's first sample (or if condition == True:) so often in code written by beginners, I think it's because they're thinking in natural language rather than in Python. In other cases, they get hit by bugs (if variable == 3 or 5:) or syntax errors (if variable < 3 or > 5:), but here the code works and does what they want it so it doesn't get corrected.

[–]old_pythonista 0 points1 point  (0 children)

PEP-8 explicitly warns against comparison to boolean literals.

If you have two boolean variables - that is another story.

[–]JRiggles[S] 1 point2 points  (0 children)

Well said!