AI engineering glossary · Python core

What is short-circuit evaluation?

Short-circuit evaluation: The rule that and/or stop evaluating as soon as the result is known. In A and B, B is skipped if A is false; in A or B, B is skipped if A is true. This avoids unnecessary work and can guard against errors.

Level: intermediateTopic: Python core

Short-circuit evaluation: an example

if d != 0 and total / d > 2: never divides by zero, because when d is 0 the second part is not evaluated.

Related terms

More Python core terms

Where you learn it

Short-circuit evaluation is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.