short-circuit evaluation

Stopping the evaluation of and or or as soon as the answer is certain, so the right-hand side may never run.

In more detail

False and anything is False, and True or anything is True, so Python skips the second part. That makes guards safe: len(s) > 0 and s[0] == "x" never indexes an empty string.

Related terms

Taught in

References

Certification courses