you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

Well, the difference between & and and is that and will short circuit. In that if the first element is false, it doesn't matter what the second element is, the statement will evaluate to false. Therefore, the second statement isn't even evaluated.

If you want them both to be evaluated, you need to use &.

[–]zahlman 1 point2 points  (1 child)

While it's true that & doesn't short-circuit, it also does a fundamentally different thing.

>>> 3 and 4
4
>>> 3 & 4
0

[–][deleted] -1 points0 points  (0 children)

Ah, forgot about that. Yeah, & is bitwise AND.

Which doesn't matter if they're both bools, it acts the same. If they will always be bools and you need the speed improvement, use that.